How to write to named Linux pipe from PHP? -
i have following bash script:
server_control_pipe="/var/custom_pipe_file_name" init_script="/usr/sbin/service [somedaemon]" mkfifo -m 666 "$server_control_pipe" while read line <"$server_control_pipe" echo "received $line" if [[ "$line" == 'stop' ]]; $init_script stop elif [[ "$line" == 'start' ]]; $init_script start elif [[ "$line" == 'stoppipe' ]]; break fi echo "waiting..." done echo "end"
...and following php script:
<?php define('server_control_pipe', "/var/custom_pipe_file_name"); if(false === file_put_contents(server_control_pipe, "start\n", file_append)) throw new exception("could not write server control pipe");
when running php script, loop in bash script seems terminate , bash script outputs end.
to try find out why that, replaced php script code:
<?php define('server_control_pipe', "/var/custom_pipe_file_name"); $f = fopen(server_control_pipe, 'w'); if(false === $f) throw new exception("could not open server control pipe"); $ret = fwrite($f, 'start\n'); if(false === $ret) throw new exception("could not write server control pipe"); fclose($f);
i found out bash script loop terminates whenever fopen
called.
so question boils down to: how have open pipe in php in order not break bash script loop?
if want script run time should have while true instead of while read line, eg:
while : echo "press [ctrl+c] stop.." sleep 1 done
if read line read file contents of file @ state , finish execution.
Comments
Post a Comment