1

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?

mavili
3,4344 gold badges32 silver badges46 bronze badges
asked Sep 2, 2013 at 9:11

4 Answers 4

1

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.

answered Sep 2, 2013 at 9:14
Sign up to request clarification or add additional context in comments.

Comments

0

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.

answered Sep 2, 2013 at 9:14

Comments

0

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');
answered Sep 2, 2013 at 9:15

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.
what errors do you get? do you have error_reporting on? any indication of what's wrong at all?
OK. I'm 100% sure that 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.
0
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

answered Sep 2, 2013 at 9:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.