aniraj Posted June 6, 2011 Share Posted June 6, 2011 Hi, I have this command with me nohup $path -h $source:11211 -b 0 -d $destination:11211 -N $destination -F -A -v>/tmp/mylog.log I have written a remote execution function using expect module in php. I want the command to run on a local box and update mylog , I want to initiate this command on the remote box from my local php script but my script shouldn't wait for this to continue. i had tried giving & in the end. Tried forking the command in another script ( Here i got the desired process running, but my main script waits for this one to complete ) Any leads? Quote Link to comment https://forums.phpfreaks.com/topic/238532-cant-run-a-php-command-in-background-on-a-remote-box-using-expect-module/ Share on other sites More sharing options...
Adam Posted June 6, 2011 Share Posted June 6, 2011 Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends. Edit Never-mind, I just noticed you're already doing that. Are you running on safe-mode? Quote Link to comment https://forums.phpfreaks.com/topic/238532-cant-run-a-php-command-in-background-on-a-remote-box-using-expect-module/#findComment-1225769 Share on other sites More sharing options...
aniraj Posted June 6, 2011 Author Share Posted June 6, 2011 system() is same as shell_exec() right? i've tried that, i even tried writing the command to a shell script, copying the script using scp and tried executing the script on the remote box using my remote_execution function, this works fine for all the commands, but with an & , the thing gets stuck. Quote Link to comment https://forums.phpfreaks.com/topic/238532-cant-run-a-php-command-in-background-on-a-remote-box-using-expect-module/#findComment-1225783 Share on other sites More sharing options...
Adam Posted June 6, 2011 Share Posted June 6, 2011 How exactly are you trying to use &? Try using exec - that just executes a given command but doesn't return the output. Quote Link to comment https://forums.phpfreaks.com/topic/238532-cant-run-a-php-command-in-background-on-a-remote-box-using-expect-module/#findComment-1225813 Share on other sites More sharing options...
aniraj Posted June 6, 2011 Author Share Posted June 6, 2011 see, using shell_exec() or system() or whatever, i can run a command in background using & , eg:- shell_exec("command &"), the same doesn't work with remote execution. i thought it was because i didn escape &. tried shellescapearg("&") also . Didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/238532-cant-run-a-php-command-in-background-on-a-remote-box-using-expect-module/#findComment-1225815 Share on other sites More sharing options...
Adam Posted June 6, 2011 Share Posted June 6, 2011 So the problem is only occurring when you're trying to remotely execute something - how are you actually executing remote commands? Quote Link to comment https://forums.phpfreaks.com/topic/238532-cant-run-a-php-command-in-background-on-a-remote-box-using-expect-module/#findComment-1225825 Share on other sites More sharing options...
aniraj Posted June 6, 2011 Author Share Posted June 6, 2011 i wrote this function function remote_execution($remote_machinename, $command_to_be_executed) { global $username,$password; ini_set("expect.loguser", "Off"); $stream = fopen("expect://ssh $username@$remote_machinename $command_to_be_executed", "r"); $cases = array ( array (0 => "password:", 1 => "password"), array ("yes/no)?", "yesno") ); switch (expect_expectl ($stream, $cases)) { case "password": fwrite ($stream, "$password\n"); break; case "yesno": fwrite ($stream, "yes\n"); break; default: die ("Error was occurred while connecting to the remote host!\n"); } $output = ""; while ($line = fgets($stream)) { $output = $output.$line; } fclose ($stream); return $output; } Quote Link to comment https://forums.phpfreaks.com/topic/238532-cant-run-a-php-command-in-background-on-a-remote-box-using-expect-module/#findComment-1225827 Share on other sites More sharing options...
Adam Posted June 6, 2011 Share Posted June 6, 2011 Have a try with popen instead. Quote Link to comment https://forums.phpfreaks.com/topic/238532-cant-run-a-php-command-in-background-on-a-remote-box-using-expect-module/#findComment-1225836 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.