开发者

What is the best way to run a PHP script multiple times asynchronously in windows?

Setup: Windows XP, XAMP with PHP 5

Hello! I have searched stackoverflow, and googled around, but i can't seem to find what i'm looking for (think). Someone has mention using windows scheduler, but i don't think that is appropriate for this use. CGI Cron job has also been mentioned.

Is it possible to 开发者_如何学Pythoncreate a batch script that runs this multiple times:

"C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"

Will it be asynchronous?

What i want to do: I have created a user class that runs random requests. I'm storing statistics of time and usage from that object to a database when it is finished running.

I want to run this script asynchronous (Maybe 100 or more instances of it) so that i can simulate a great usage of the requests.

Any idea of how i can do this?

Thanks in advance


You can use a loop to start as many instances as you like. They should be started as different threads if you do not insist of waiting for a result.


spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"
spawn "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"

... and so forth?


Well this will depend on your machine , but basically you could create a bat script... simple loop for 1 to 100


FOR /L %i IN (1,1,100) DO (
  "C:\Program Files\Xampp\PHP\PHP.exe" -f "c:\htdocs\my_script_to_run.php"

)

and then get it to sleep inside the loop. There are versions that don't have the sleep command as I've seen in this link http://malektips.com/xp_dos_0002.html

try it out... with the ping trick you might even get some entropy in the times..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜