Can I directly serialize to a file using PHP's thrift library?

[亡魂溺海] 提交于 2019-12-22 18:03:08

问题


Related: Apache Thrift: Serializing data

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 ?

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.


回答1:


Try extending TPhpStream by overriding:

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

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.

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.



来源:https://stackoverflow.com/questions/8499076/can-i-directly-serialize-to-a-file-using-phps-thrift-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!