Php+shell method of implementing multithreading
Here's how to implement multithreading with Shell scripting.
Write a simple PHP code first. This is to allow the script to run for a longer time. Easy to see effect, sleep a bit. Oh. First look at the test.php code: LS
PHP Code:
?
| 123456 |
<?php for($i=0;$i<10;$i++) { echo$i; sleep(10);} ?> |
Look at the code of the shell script, very easy
?
| 12345 |
#!/bin/bashfori in 1 2 3 4 5 6 7 8 9 10do /usr/bin/php-q /var/www/html/test.php &done |
Notice that the line in the request for PHP code has a & symbol, this is the key, no words can not be multithreaded,& Express service push to the background to run. Therefore, in the shell every time the loop does not have to wait for the PHP code to run all finished in the request next file, but at the same time. This implements the multi-threaded, below run under the shell to see the effect, here you will see 10 test.php process to run again, and then use the Linux timer. Request this shell on a timed basis to handle some tasks that require multiple threads. For example, when downloading in bulk. Very good!
Php+shell Method of implementing multithreading