Protobuf-php: unable to successfully execute protoc-gen-php

I cloned the Protobuf-PHP repository: https://github.com/drslump/Protobuf-PHP.git , which I found at https://github.com/drslump/Protobuf-PHP , and I worked on installation and configuration problems about 12 hours trying to get protoc-gen-php to convert the proto file to a PHP class.

I am running PHP version 5.3.2 and here is what I did:

  • Installed PEAR v1.9.4
  • Installed Console_CommandLine and ran PEAR_ENV.reg to set the PEAR environment variables.
  • I tried every permutation that I can think of in order to try to get this plugin to generate a PHP class file, and every attempt failed.

I have a proto file that we use with the C # project in the root folder, where I checked the proto-gen-php project (see below).

message AuditLogEntry { required int64 ID = 1; required int64 Date = 2; required string Message = 3; optional int32 User_ID = 4; optional string User_Username = 5; optional int32 ImpUser_ID = 6; optional string ImpUser_Username = 7; optional string RemoteIP = 8; } message AuditLogQuery { optional int64 DateRangeStart = 1; optional int64 DateRangeEnd = 2; optional string Search = 3; optional int32 UserID = 4; optional int32 Limit = 5; optional int32 Offset = 6; } message AuditLogResult { repeated AuditLogEntry LogEntries = 1; optional int32 TotalResults = 2; } 

Here are just a few of the problems I am having:

  • When I try to execute the most basic implementation:

     protoc-gen-php.bat AuditLog.proto 

    I get this error:

    Could not open input file: @bin_dir @ \ protoc-gen-php The file name, directory name, or volume label syntax is incorrect.

    I can not find information about this error on the Internet. Is there a configuration problem with installing one of the packages I'm using? Any ideas?

  • Due to the error above, I changed this line in the protoc-gen-php batch file:

     "%PHPBIN%" -d display_errors=stderr -d log_errors=On -d error_log=Off "@ bin_dir@ \protoc-gen-php" %* 

    to

     "%PHPBIN%" -d display_errors=stderr -d log_errors=On -d error_log=Off "protoc-gen-php.php" %* 

Now, when I run the same command given in task 1, I get the following output:

 The filename, directory name, or volume label syntax is incorrect. Protobuf-PHP @ package_version@ by Ivan -DrSlump- Montes C:\Development\SkedFlex\php-proto-buffers\AuditLog.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 (eg absolute and relative) are equivalent (it harder than you think). ERROR: protoc exited with an error (1) when executed with: protoc \ --plugin=protoc-gen-php="C:\Development\SkedFlex\php-proto-buffers\protoc-gen-php.php.bat" \ --proto_path="C:\Development\SkedFlex\php-proto-buffers\library\DrSlump\Protobuf\Compiler\protos" \ --php_out=":./" \ "C:\Development\SkedFlex\php-proto-buffers\AuditLog.proto" 

I tried many options for the command using -i, -o, as indicated in the manual: http://drslump.github.com/Protobuf-PHP/protoc-gen-php.1.html , but this may not seem to improve ..

Finally, I resorted to trying to execute protoc directly:

 protoc --plugin=protoc-gen-php --php_out=./build AuditLog.proto 

this is mistake:

 --php_out: protoc-gen-php: The system cannot find the file specified. 

I am at the point where I am stuck. Does anyone have any experience with protoc-gen-php that can help me solve the problems I am having?

+7
source share
1 answer

. A byte file cannot be used directly after checking it from the repository, it changes when the Pear package is created. Therefore, you must install Protobuf-PHP with Pear if you do not want to modify the source code of the library in any way.

 pear channel-discover pear.pollinimini.net pear install drslump/Protobuf-beta 

If you do not want to install from Pear, you will have to manually modify the protoc-gen-php.bat , replacing the last line with something similar to this:

 C:\path\to\php.exe -d display_errors=stderr -d log_errors=On -d error_log=Off c:\path\to\protobuf-php\protoc-gen-php %* 

To fix the error "The file is not within any specified path ...", you must make sure that any proto file specified as an argument is inside a specific include path. The Google protoc component protoc not try to guess what include paths are, so we must provide them manually in all cases.

 protoc-gen-php.bat -i . AuditLog.proto 

This should allow you to generate PHP files for your proto-messages, although the script is not tested on Windows systems, like Linux and OSX. If you find any problems, you can report them directly on the project website if you want.

+3
source

All Articles