I am trying to execute a php script from within another php script. I cant seem to get it to pass the parameters properly. What am I doing wrong?
First script called
<?php
$item = "hello";
$item2 = "world";
exec("php scriptToBeExecuted.php arg1=".$item." arg2=".$item2." &");
?>
Script to be executed
<?php
var_dump($argc);
if (isset($argv))
{
parse_str(implode('&', array_slice($argv, 1)), $_GET);
$item= $_GET['arg1'];
$item2= $_GET['arg2'];;
}
else
{
echo "not set";
}
?>
I do not recieve any output in a browser when I try to execute this. Which isn't the main issue because I am using this to make database calls but like I said, after hours of fussing with this, it will not execute properly or at all
You have to either run this script as a command or as a web page. If the former, there is no such thing as $_GET. If the latter, there is no $argv. Try this.
First script called
<?php
$item = "hello";
$item2 = "world";
exec("php scriptToBeExecuted.php $item $item2");
?>
Script to be executed
<?php
var_dump($argc);
if (count($argv) === 3) {
$item= $argv[1];
$item2= $argv[2];
} else {
echo "not set";
}
?>
See also: