dale/phpickle
Composer 安装命令:
composer require dale/phpickle
包简介
PHP package for support python pickle format
README 文档
README
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.
dale/phpickle 适用场景与选型建议
dale/phpickle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dale/phpickle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dale/phpickle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-29