How to start a background process with PHP exec (linux)? -
i know there's lot of posts on topic, solutions mentioned there don't seem work me.
i'm building chat client , want keep process running in background, listen incoming messages on account.
here's code:
$command = "cd classes/chat/inc/ && /usr/bin/php5 client.php --mysql_server=localhost --mysql_username=root --mysql_password= --mysql_database=covide --gtalk_user=xxx --gtalk_password=xxx --user_id=".$_session['user_id']." &> /dev/null &"; exec($command);
i've tried lot of options instead of this:
&> /dev/null &
like > /dev/null 2>/dev/null & or > testoutput.php 2>&1 & echo $! (from various posts on forum), no success. have idea on how should fixed?
i have working version of this. instead of using exec(); use curl post run our background process. problem timing out limitations. can have background process run through "listen incoming messages" task, @ end call instance of , close current instance.
you can use @ beginning of process make sure doesn't exit prematurely, did not find necessary, ran fine when following wasn't implemented, still:
/* close our connection calling file */ while(ob_get_level()) ob_end_clean(); header('connection: close'); ignore_user_abort(); ob_start(); echo('running in background.'); $size = ob_get_length(); header("content-length: $size"); ob_end_flush(); flush();
Comments
Post a Comment