Martin Jacob Martin Jacob - 6 months ago 23
PHP Question

How to call PHP file from a shell script file

I need a shell script which has a loop. In each loop iteration it needs to call a PHP file with some parameters. Is there any way to do it?


In your php file named test.php, for example

//like programs in c language, use $argc, $argv access command line argument number and arguments, uncomment below two line to dump $argc and $argv
//var_dump($argc); //an integer
//var_dump($argv); //an array with arguments
//use args and do anything you want
echo "do my job\n";

then create a shell script named

#! `which bash`
php=`which php`
while [[ $i -ge 0 ]];
$php test.php 1 2

put the two files into the same directory. Then run command in the terminal