I'm playing with a script that I had to call from another php file. From file update.php, at the beginning I have to start the script by calling its file serv.php. But, in order for serv.php to work I had to pass a couple of arguments. The command to start serv.php from command line is as follow:
php c:\path_to_folder\serv.php run --argument1="some_text" --argument2="some_text" --port=some_port
If we presume that update.php and serv.php are at the same folder, how to call serv.php from within update.php?
4 Answers 4
Send $argv of serv.php from serv.php to update.php (see http://php.net/manual/en/reserved.variables.argv.php). I.e. in update.php you will have another $argv, so you have to send list of command line parameters in array with different name.
Comments
use exec or system call within your calling PHP Script. do mention full path of PHP CLI i.e. /user/bin/php or whatever path is there in your server.
Comments
You can execute a system command using the exec function. PHP exec().
You can call your page serv.php from your update.php script as such
exec('php c:\path_to_folder\serv.php run --argument1="some_text" --argument2="some_text" --port=some_port');
3 Comments
exec('php c:\inetpub\wwwroot\update\server.php --argument1="some_text" --argument2="some_text" --port=some_port'); that doesn't work. shell_exec also.exec('c:\windows\system32\cmd.exe "php c:\path_to_file\serv.php run --arg1="some_text" --arg2="some_text" --port=some_port"'); starts cmd.exe. So what's left is how to pass the starting statement php c:\path_to_file\serv.php run --arg1="some_text" --arg2="some_text" --port=some_port to it.shell_exec("php c:\path_to_folder\serv.php some_text some_text some_port ");
usually is php -f or php5-cli instead of php and some servers don't even require the path to the php folder
This is one of my query:
$ex=$setting[8]." ".dirname(__FILE__)."/sendmail.php NewMem ".$_SESSION['id']." ";
if(substr(php_uname(), 0, 7) == "Windows")
pclose(popen("start /B ".$ex,"r")); /windows server
else
shell_exec($ex." > /dev/null 2>/dev/null &");//Apache
where $setting[8] is php -f or php5-cli, ".dirname(__FILE__)."/sendmail.php is the path to the file, and the others are the arguments .
To retrieve the passed arguments use $argv that contains all the other parameter $argv[0] is the file path.
Note that each space define a new argument