views:

39

answers:

1

I have 2 short scripts. The first, an awk script, processes a large file and prints to a named pipe 'myfifo.dat'. The second, a Perl script, runs a LOAD DATA LOCAL INFILE 'myfifo.dat'... command. Both of these scripts work when run locally like so:

lee.awk big.file &
lee.pl

However, when I call these scripts from a PHP webpage, the named pipe blocks:

$awk="/path/to/lee.awk {$_FILES['uploadfile']['tmp_name']} &";
$sql="/path/to/lee.pl";

if(!exec($awk,$return,$err)) throw new ZException(print_r($err,true)); //blocks here
if(!exec($sql,$return,$err)) throw new ZException(print_r($err,true));

If I modify the awk and Perl scripts so that they write and read to a normal file, everything works fine from PHP. The permissions on the fifo and the normal file are 666 (for testing purposes). These operations run much more quickly through a named pipe, so I'd prefer to use one. Any ideas how to unblock it?

ps. In case you're wondering why I'm going to all this aggravation, see this SO question.

+1  A: 

As you probably know, when you open a named pipe for write you will block until somebody else opens it for read. I presume this is why you have the "&" at the end of the command line in the 1st exec() call.

But does PHP respect that syntax? I'm no PHP expert, but if that is not the correct method to have PHP exec() return before the child has finished executing then the two exec() calls will be serialized and that would totally explain this blocking behavior.

joefis
I have no specific knowledge for the questioned problem, but my guts tell me, that this is a promising route to search. +1
Boldewyn