This article mainly introduces the implementation of multi-threaded PHP method, interested in the reference of friends, I hope to be helpful to everyone.
This paper describes the Php+shell implementation of multi-threading methods, as follows:
Here's how to implement multithreading with Shell scripting.
First write a simple PHP code, here in order to make the script execution time longer, convenient to see the effect, sleep, hehe! First look at the test.php code:
PHP Code:
<?phpfor ($i =0; $i <10; $i + +) { echo $i; Sleep (10);}? >
Look at the code of the shell script, very simple
#!/bin/bashfor I 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, not add the words is not able to multi-threaded,& service push to the background execution, so in the shell every time the loop does not have to wait for the PHP code to complete after the request of the next file, but at the same time , so that the implementation of multi-threading, under the shell to see the effect, here you will see 10 test.php process and then run, and then use the Linux timer, timed to request the shell, in the processing of a number of multi-threaded tasks, such as bulk download, very useful!
Summary: the above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP tips for caching with file storage
PHP for uploading image files of the function of the detailed
PHP uses regular expressions to extract links from content
PHP recursive traversal for unlimited classification
PHP Process Control and mathematical operations