The example of this article describes the Php+shell implementation of multithreading method. Share to everyone for your reference. Specifically as follows:
Here's how to use the shell script to implement multithreading.
First write a simple PHP code, here in order to allow the script to perform longer, easy to see the effect of sleep, oh! First look at the test.php code:
PHP Code:
?
| 1 2 3 4 5 6 |
<?php for ($i =0 $i <10; $i + +) {echo $i; sleep (a);}?> |
Look at the code for the shell script, very simple
?
| 1 2 3 4 5 |
#!/bin/bash for I in 1 2 3 4 5 6 7 8 9 ten do/usr/bin/php-q/var/www/html/test.php & Done |
Notice that there is a & symbol on the line requesting PHP code, this is the key, without words is not to do multithreading,& Express service push to the background execution, therefore, in the shell of each loop without waiting for PHP code all executed in the request next file, but at the same time , so that the implementation of multithreading, below the shell to look at the effect, here you will see 10 test.php process and then run, and then use the Linux timer, timed request this shell, in the processing of a number of tasks that require multithreading, for example, the bulk of the download, very easy to use!
I hope this article will help you with your PHP program design.