Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protobuf-PHP: Cannot Successfully Execute protoc-gen-php

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

I am running PHP Version 5.3.2, and here's what I've done:

  1. Installed PEAR v1.9.4
  2. Installed Console_CommandLine, and ran PEAR_ENV.reg to set the PEAR environment variables.
  3. I have tried every permutation I can think of to try to get this plugin to generate a PHP class file, and every attempt has failed.

I have a proto file that we're using with a C# project in the root folder where I checked out 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 problems that I'm having:

  1. When I attempt 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 filename, directory name, or volume label syntax is incorrect.

    I cannot find any information regarding this error online. Is there a configuration problem with the installation of one of the packages that I'm using? Any ideas?

  2. Because of 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 problem 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 (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="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 variations of the command using -i, -o as specified in the manual: http://drslump.github.com/Protobuf-PHP/protoc-gen-php.1.html, but cannot seem to make headway on this...

Finally I resorted to attempting to execute protoc directly:

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

this is the error:

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

I am at a point where I'm stuck. Is there anyone that has experience with protoc-gen-php that can help me resolve the problems that I am having?

like image 533
Darin Peterson Avatar asked Aug 23 '12 18:08

Darin Peterson


1 Answers

The .bat file cannot be used directly after checking it out from the repository, it is modified when creating a Pear package. Thus you should install Protobuf-PHP using Pear unless you want to modify the source code of the library somehow.

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

If you don't want to install from Pear you'll have to manually modify the protoc-gen-php.bat file 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 %*

In order to fix the "File does not reside within any path specified..." error you must make sure that any proto file given as argument resides inside a defined include path. Google's protoc compiler does not try to guess what the include paths are so we need to provide them manually in all cases.

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

That should allow you to generate the PHP files for your proto messages, although the script is not as tested in Windows systems as is in Linux and OSX ones. If you find any issues you can report them directly at the project site if you wish.

like image 144
DrSlump Avatar answered Dec 03 '22 07:12

DrSlump