Reputation: 1813
I have a perl script that performs operations on a large amount of data and builds a table. I want to call upon this script from PHP. I am passing tabular data which contains strings, quotes, and all kinds of nastyness so a simple
passthru('./path/to/pl $var1 $var2');
won't do. I was thinking of JSON encoding the data then base64 encoding the JSON and passing like:
passthru('./path/to/pl "$base64edJSON"');
Is this a proper way or is there a better way? The perl script must return the completed table back to the PHP script through a return, stdout, or some other means.
Upvotes: 2
Views: 574
Reputation: 39158
On the PHP side, open a bidirectional pipe to the Perl process and write into its pipe. On the Perl side, read from STDIN.
To return the data, write to STDOUT in Perl. In PHP, read from the pipe.
You need no encoding.
Upvotes: 1
Reputation: 12439
You can call the perl script using proc_open. Then you can feed the input to it through stdin and get the output/errors from stdout. The Perl script will run as a pipe.
This gets around any messiness with temporary files.
Upvotes: 2
Reputation:
I would serialize the contents from PHP to a file and then load it into Perl. You can use the CPAN module PHP::Serialization.
Upvotes: 0