我可以使用PHP的Thrift库直接序列化为文件吗? [英] Can I directly serialize to a file using PHP's thrift library?

查看:115
本文介绍了我可以使用PHP的Thrift库直接序列化为文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关: Apache Thrift:序列化数据

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

Hi guys : I am noting that the PHP thrift extensions don't appear to have a TFileTransport class. This leads me to wonder : what is the mechanism for writing a thrift object to a FILE in PHP ?

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

Unfortunately, available documentation is focused on the client/server model for using thrift : but I need to use PHP to serialize binary thrift files on disc, which contain a stream of thrift objects.

推荐答案

尝试通过覆盖扩展TPhpStream:

Try extending TPhpStream by overriding:

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

,您可能还需要更改打开方法以打开您选择的写入文件.如果需要,这里是关于php流的不错的教程.

and you would also probably need to alter open method to open write file of your choosing. In case you need it, here is nice tutorial about php streams.

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

If that does not work out for you, consider using TMemoryBuffer to serialize to string, and than you will find your way to put that into a file.

这篇关于我可以使用PHP的Thrift库直接序列化为文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆