system("php ./somescript.php $something >/dev/null &");
I’m new to PHP and I am deciphering someone else’s code and can’t figure out what this code is doing. I looked at the system documentation here so I understand that it will execute the PHP script in somescript.php, and that $something is a parameter passed to that script…but after that I’m lost.
Also, what part of the script does $something get passed to? How does it know what function in somescript.php to call first?
It’s basically running the
./somescript.phpprogram, with$somethingas a command-line parameter.It explicitly ignores the output by routing it to the
nulldevice.And it runs it in its own shell and doesn’t wait for it to finish (that’s the
&bit on the end).I assume that
somescript.phpis a program that runs some kind of background task. It probably takes a bit of time to run, but your main program doesn’t need to know about the results of that task, so it doesn’t need to wait for it to finish.[EDIT]
$somethingis passed into the program as a command-line argument. When PHP is called from the command line, the arguments are populated into the$argvarray.See the PHP manual for more info: