How to call PHP file from a shell script file [duplicate]

孤者浪人 提交于 2019-11-29 08:24:47

In your php file named test.php, for example

<?php
//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";
exit(0);

then create a shell script named test.sh

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

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

bash test.sh

If this means a Linux/Unix shell

for i in `seq 4`; do
    php myscript.php param1 param2
done

But since PHP has loops too, you can do this in PHP as well.

for ($i = 0; $i < 4; $i++)
    system("php myscript.php param1 param2");
#!/bin/sh
#
#Script to test for loop
#
#

    while [condition] 
    do
    php test.file
    done
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!