简体   繁体   中英

launching php script running on server (and opening sockets) from a php page

I'd need you precious help on a matter I am spending hours on. Scope: Apache2 and PHP running on a raspberry pi; Premise: my little knowledge of Linux environment!

The objective: launching a long-run php script, that opens sockets, from another php script running as webpage. In other terms, the application is a chat and I need to start the php server script form a web page, for my convenience.

The issue: if I run it from the the console, logged as "pi", with the following command

php -q /var/www/chatSocket.php > /var/www/tmp/socketProcessOutput.txt 2>&1 & echo $!

it works like a charm, but if it try to do so from a script, with the following (don't mind the concatenated strings and assignment of output to variables - it made no difference removing them):

$result .= "Result of pkill (killed process): " .shell_exec('sudo pkill -f SongWebSocket.php') ."\n";
$result .= "Launching new  process: id returned:". shell_exec('php -q /var/www/chatSocket.php > /var/www/tmp/socketProcessOutput.txt 2>&1 & echo $!')  ."\n";
$result .= "Checking running SongWebSocket.php process:"  ."\n";
$result .= shell_exec('ps -A aux| grep -e SongWebSocket.php -e USER')  ."\n";

.. it does not work (it seems like it launch the script but the sockets ar not open).

Any clue why this happens?

Also, and this can be for my little knowledge of Linux, why i get a dioffrent aoutput from the command ps aux| grep -e SongWebSocket.php -e USER if I launch it from the shell, as user pi, or from the sript, as www-data user.

I Look forward for your help. Thanks in advance! Marco.

www-data user doesn't have the permisson I guess. why not add "sudo" for every shell_exec line? (sudo starts the programm with root permission). it's not pretty and not secure but it might work on you local home-network. sudo php ... sudo ps -A aux etc. In addition you should make sure that the php safe_mode is off. you can see that by adding phpinfo(); to you php code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM