【问题标题】:Can I directly serialize to a file using PHP's thrift library?我可以使用 PHP 的 thrift 库直接序列化到文件吗?
【发布时间】:2012-01-19 21:48:15
【问题描述】:

相关:Apache Thrift: Serializing data

大家好:我注意到 PHP thrift 扩展似乎没有 TFileTransport 类。这让我想知道:在 PHP 中将 thrift 对象写入 FILE 的机制是什么?

不幸的是,可用的文档集中在使用 thrift 的客户端/服务器模型上:但我需要使用 PHP 来序列化磁盘上的二进制 thrift 文件,其中包含一个 thrift 对象流。

【问题讨论】:

    标签: php file serialization thrift


    【解决方案1】:

    尝试通过覆盖来扩展 TPhpStream:

    private static function inStreamName() {
        if (php_sapi_name() == 'cli') {
          return 'php://stdin';
        }
        return 'php://input';   }
    

    您可能还需要更改打开方法来打开您选择的写入文件。如果你需要的话,这里是nice tutorial about php streams.

    如果这对您不起作用,请考虑使用 TMemoryBuffer 序列化为字符串,然后您会找到将其放入文件的方法。

    【讨论】:

    • 据我阅读,它会检查 php 是否作为命令行启动(cli = 命令行界面),如果是,则使用标准 unix 输入。否则使用http服务器提供的输入流。
    猜你喜欢
    • 1970-01-01
    • 2012-09-01
    • 2016-03-22
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多