Your call is failing because you're using a web-style syntax (?parameter=value) with a command-line invokation. I understand what you're thinking, but it simply doesn't work.
You'll want to use $argv instead. See the PHP manual.
To see this in action, write this one-liner to a file:
<?php print_r($argv); ?>
Then invoke it from the command-line with arguments:
php -f /path/to/the/file.php firstparam secondparam
You'll see that $argv contains the name of the script itself as element zero, followed by whatever other parameters you passed in.
Your call is failing because you're using a web-style syntax (?parameter=value) with a command-line invokation. I understand what you're thinking, but it simply doesn't work.
You'll want to use $argv instead. See the PHP manual.
To see this in action, write this one-liner to a file:
<?php print_r($argv); ?>
Then invoke it from the command-line with arguments:
php -f /path/to/the/file.php firstparam secondparam
You'll see that $argv contains the name of the script itself as element zero, followed by whatever other parameters you passed in.
try echo exec("php /var/www/unity/src/emailer.php 123"); in your script then read in the commandline parameters.
On most systems, the kernel limits the size of the arguments to the execve() syscall (command line args + environment vars). On Linux, the limit is related to the maximum stack size, though usually you'd get at least 2 MB total for the default stack size limit of 8 MB. It also limits a single argument to 128 kB, see e.g. Is there a maximum to bash file name expansion (globbing) and if so, what is it? and Raise 128KiB limit on environment variables in Linux
If PHP runs sh -c 'command line' when you call exec("command line") then the argument to -c could well exceed that 128 kB limit. The fact that the command line gets subsequently split into distinct words by the shell wouldn't help.
When you have this many arguments, you want to pass them to GNU Parallel via standard input (stdin) or via files.
I would do something like (untested):
$f = popen("parallel","w");
fwrite(
commands);
close ($f);
This way you may be able to avoid the temporary file.
Passing parameters to a shell script from PHP.
Its all about the "strings", and when to "double quote" for expansion.
<?php
/* exec("/csvexport.sh $table"); */
/* double quote here because you want PHP to expand $table */
/* Escape double quotes so they are passed to the shell because you do not wnat the shell to choke on spaces */
$command_with_parameters = "/path/csvexport.sh \"${table}\"";
$output_from_command = "";
$command_success = "";
/* double quote here because you want PHP to expand $command_with_parameters, a string */
exec("${command_with_parameters}", $output_from_command, $command_success);
/* or to keep it simple */
exec("/path/csvexport.sh \"${table}\"");
/* show me what you got */
echo"${command_success}\n${output_from_command}\n";
?>
BTW: I did not test this snippet.
I'm not a PHP guy, but it seems you'll need to do something like
exec(escapeshellcmd("/csvexport.sh \"$query\" $table"));
Does PHP have a function where you can call the command and pass the arguments separately?
some_exec_function("/csvexport.sh", $query, $table); # ???
There is php function escapeshellarg for this. You enter whatever string you need and result is string formated so you can use it as one argument in shell:
$rawArgument = "I'm a directory";
$escapedArgumment = escapeshellarg($rawArgument);
exec("ls $escapedArgumment");
You'll need to double escape your slashes correctly to ensure they don't get eaten by the string.
Part of your problem is that \' is being eaten and passed to the command line as just '.
Compare these:
echo 'ls I\'m\ a\ directory';
echo "\n";
echo "ls I\'m\ a\ directory"; //Note double quotes
echo "\n";
echo 'ls I\\\'m\\ a\\ directory';
echo "\n";
echo "ls I\\\'m\\ a\\ directory"; //Note double quotes
Results in:
ls I'm\ a\ directory
ls I\'m\ a\ directory
ls I\'m\ a\ directory
ls I\\'m\ a\ directory
So what you really want is either of these:
exec('ls I\\\'m\ a\ directory')
exec("ls I\'m\ a\ directory")
I would recommend writing the command into a PHP variable and then using that as the command itself:
$command = "pushmsg echo $name echo $phone echo $core";
$output = exec($command);
You can catch the last line of the output of exec in the $output variable. Or use shell_exec to catch the full output of the command.
<html>
<body>
<link rel="stylesheet" type="text/css" href="style.css">
<?php
$name = $_POST["name"];
$phone = $_POST["phone"];
$core = $_POST["core"];
$command = "pushmsg echo $name echo $phone echo $core";
$output = exec($command);
?>
<h1>request submited successfully</h1>
<p>thanks for sending yout request, <?php echo $_POST["name"]; ?>.<br>
a text will be sent to <?php echo $_POST["phone"]; ?> once your details have been confirmed.
</p>
<div class="center">
<button class="button" action="/index.html">home page</button>
</div>
</body>
</html>
You need to change it to
$command = "pushmsg $name $phone $core";
$output = exec($command);
Without error information, I'm not sure if this is the entire problem, but I'd start with this:
Arguments as read by $argv are space-delimited. The following code:
/usr/bin/php /xxx.yyy.net/TESTS/sendit.PHP $TO $SUB $BODY $FROM > /dev/null &
is executing as follows in your example:
/usr/bin/php /xxx.yyy.net/TESTS/sendit.PHP [email protected] Yadda This is a test [email protected] > /dev/null &
That makes $argv[3] == 'This' and $argv[4] == 'is'.
Without any debugging I don't think anyone will be able to give you an answer.
You have to remember that *nix is case sensitive. So you have to make sure that /xxx.yyy.net/TESTS etc are actually in correct case, spelled correctly.
Also I would suggest not sending everything to /dev/null and maybe to a file. Simply because /usr/bin/php could be using different config (happened to me before) and it didnt work as espected when I ran scripts in crontab.
You need to find out some more info! Check php logs, see what that script gives you when you run it from terminal.
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.
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.