joeyoun9 / phpickle Goto Github PK
View Code? Open in Web Editor NEWThis project forked from terryf/phpickle
Python pickle format support for php
This project forked from terryf/phpickle
Python pickle format support for php
Phpickle is a set of PHP classes that allow you to read and write the python pickle format. It is useful for integrating python and php applications together, for example to read django session data from a php application. ==============Basic usage: ---- require_once "phpickle.php"; $data = phpickle::loads($pickled_string); --- If you want to unpickle from something that can be treated as a php stream, then: ---- require_once "phpickle.php"; $data = phpickle::load_stream("pickled_file.pickle"); $data = phpickle::load_stream("http://www.pickler.com/mydata"); // and others --- If you want to unpickle data that was stored by the default django session handler, then: ---- require_once "phpickle.php"; $data = phpickle::loads_django_session($data_from_django_session_db); --- If you want to pickle data, then: --- require_once "phpickle.php"; $string = phpickle::dumps($data_to_pickle); --- ===============Current status: Well, unpickling simple types, lists, tuples, dicts, ints, double, strings works. Unpickling class instances also works, but of course the instances are not the same as the ones in python. Instead stdClass instances are created, with all the data properties that are in the pickle and a few extra ones as well: $inst->__python_class__ = "__main__.test"; $inst->__python_construct_args__ = array(); __python_class__ is the package.class name for the python class that this instance represents. __python_construct_args__ are the contructor arguments for creating the class instance in python. Of course, referencing really python specific things, line REDUCE op that gives it's argument to a python method to produce a result cannot be supported. Pickling support is there for simple types and arrays. Experimental support for objects is also there. Pickling back from previously unpickled data should produce the same result most of the time, but needs better test coverage. ===============Code setup: tests folder has phpunit based tests for some of the modules. Pickle is a very simple stack based language, the interpreter is in phpickle_unpickle.php and the read/write handlers for different opcodes are in the phpickle_op_handlers.pck. To generate the interpreter files, run make gen, that will generate phpickle_gen_read_ops.php and phpickle_gen_write_ops.php To debug unpickling, call phpickle_unpickler->set_debug(true) and in the read handler code, just to if ($debug). In the handler code, you can read data from the $stream, using phpickle_stream methods and push results into $stack that is a phpickle_stack instance. $memo is for memorizing things.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.