我目前正在尝试将.proto文件解析为php。我尝试过使用DrSlump's Protobuf Parser 但要么我的知识太小,要么我的Godaddy共享主机缺少一些东西。我已经用我的知识尝试了一切,但没有成功地得到我想要的东西。
所以我的问题是,是否有关于如何使其正常工作的分步教程?
我已经使用SSH安装了protoc并且还安装了
pear channel-discover pear.pollinimini.net
pear install drslump/Protobuf-beta
当前问题:
root@v0071:~/Root/var/www/xxx.com/web/test# protoc-gen-php
Protobuf-PHP 0.9.4 by Ivan -DrSlump- Montes
Error: You must provide at least 1 argument.
Type "/usr/bin/protoc-gen-php --help" to get help.
root@v0071:~/Root/var/www/xxx.com/web/test# php protoc-gen-php.php LandData.proto
Protobuf-PHP @package_version@ by Ivan -DrSlump- Montes
/var/www/clients/client1/web10/web/test/LandData.proto:
File does not reside within any path specified using --proto_path (or -I).
You must specify a --proto_path which encompasses this file.
Note that the proto_path must be an exact prefix of
the .proto file names --protoc is too dumb to figure out when two
paths (e.g. absolute and relative) are equivalent
(it's harder than you think).
ERROR: protoc exited with an error (1) when executed with:
protoc \--plugin=protoc-gen-php='/var/www/clients/client1/
web10/web/test/protoc-gen-php.php' \
--proto_path='/var/www/clients/client1/web10/web/test/
library/DrSlump/Protobuf/Compiler/protos' \--php_out=':./' \
'/var/www/clients/client1/web10/web/test/LandData.proto'
答案 0 :(得分:0)
即使这个问题很老,我还是想回答,也许有人会发现它有用。
首先,我建议您使用Protobuf
github存储库中的官方库。
所以我的理解是你试图从proto文件生成PHP clases。为此,您必须首先安装协议缓冲区编译器(protoc)。在链接的末尾,您可以找到版本。
安装protoc
的最简单方法是使用二进制文件,之后,您可以在"/protobufBinaries/bin"
后编译文件,然后在那里找到protoc
。
现在你有了protoc,你可以运行:./protoc --php_out=/var/www/html/generated_files /var/www/html/proto/example.proto --proto_path=/var/www/html/proto
注意:不要忘记指定--proto_path,否则会出错。您需要指定相同的路径,但不必包含该文件。 You must specify a --proto_path which encompasses this file.
就我而言,这些类是在/var/www/html/generated_files
生成的。