Im trying to run the function
execInBackground('start cmd.exe #cmd /k "ping google.com"');
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
on my vps but it's not working,
but when I run it exactly on my local pc in works fine, cmd open and run "ping google.com" ,what is making it not working on my vps? I added php to enviroment variables too
Related
I try to execute a .php script with the shell_exec() function on a 1&1 Linux shared Webserver (debian GNU/Linux 8 distribution).
private function callAsyncSkript(){
// Asynchron Zipping over executing a Script in a new process.
if (substr(php_uname(), 0, 7) == "Windows"){
$cmd = "start /B php .\src\Core\Services\AsynchronZip.php fileids=".$this->idQuery . " fulllink=".$this->uri;
pclose(popen($cmd, "r"));
}
else {
$cmd = "/usr/bin/php7.2-cli ".getcwd()."/src/Core/Services/AsynchronZip.php fileids=".$this->idQuery . " fulllink=".$this->uri;
shell_exec("/usr/bin/nohup ".$cmd." >/dev/null 2>&1 &"." | at now");
//shell_exec("/usr/bin/nohup ".$cmd." >/dev/null 2>&1 &");
}
}
The "/usr/bin/nohup " addition donĀ“t help to execute the script asynchron,
if iam using " | at now" the script will not be executed.
Are there some special settings i have to set or are there other options for an asynchron execution over the commandline?
I found out that the only shell available to me is a rssh. Is it possible that she is the mistake.
I am trying to run a command in CMD using PHP and get a output in web. After doing some research I came to know about exec('command', $output, $return_var) function. And i got the output when i am running ping www.google.com because after the execution is complete the command is getting end. But what I am looking for when I run the command I need to get the output Node Ready and as the execution is not getting ended and its running that's why server its waiting for the output. Is there anyway where i can get the output in this condition.
My CMD output is :
This function its helping me to run the CMD and execute the command. How will I get the output in the web??
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows") {
pclose(popen("start /B ". $cmd, "r"));
} else {
exec($cmd . " > /dev/null &");
}
}
Thank you
The following code is working on localhost xampp windows, but when i put it online godaddy shared linux hosting its not working. exec is working as i tries exec('whoami') and it outputs my account id, but the following exec command is not executing.
is there any changes i need to make it work? please guide.
$cmd = 'php file.php';
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
PHP exec are not supported on share hosting accounts: http://support.godaddy.com/groups/web-hosting/forum/topic/is-php-exec-available-or-executable/
I was trying to execute a php file thorugh php with shell_exec, this was the code:
$ex="php -f ".rtrim(dirname(__FILE__))."/sendmail.php";
if(substr(php_uname(), 0, 7) == "Windows")
pclose(popen("start /B ".$ex,"r"));
else
shell_exec($ex." > /dev/null 2>/dev/null &");
The problem is that it didn't work on my server(I have even tried without the -f), but this is ok:
$ex="php-cli ".rtrim(dirname(__FILE__))."/sendmail.php";
if(substr(php_uname(), 0, 7) == "Windows")
pclose(popen("start /B ".$ex,"r"));
else
shell_exec($ex." > /dev/null 2> /dev/null &");
Can somebody tell me why it works? Does php-cli even exists?
Thanks in advance
OS doesn't matter. You should be able to use shell_exec if it's not disabled in your php.ini
Hey there! I want to restart a live stream by hand via a php script. Everything works fine so far, but the following command causes that the script loads forever and the transcoding isn't working:
nohup openRTSP -v -c rtsp://*****.dyndns.org:665 | ffmpeg -r 5 -f mjpeg -i - http://127.0.0.1:8090/feed1.ffm > /dev/null &
Any ideas how to start that command e.g. without waiting for the output?
Not that it will necessarily solve your problem, but it should answer your question, found in the PHP comments under "exec" in which several people came across similar situations.
I combined several efforts in this
topic into one function: This will
execute $cmd in the background (no cmd
window) without PHP waiting for it to
finish, on both Windows and Unix.
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}