2012-12-13 84 views

回答

8

名爲test.php的你的PHP文件,例如

<?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); 

然後創建一個shell腳本命名test.sh

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

把兩個文件在同一目錄。然後在terminal

bash test.sh 
1

運行命令。如果這意味着在Linux/Unix外殼

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

但由於PHP有循環也可以用PHP做到這一點。

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

    while [condition] 
    do 
    php test.file 
    done