PHP asynchronous operations (swoole, gearman)
PHP asynchronous operations
Go to the topic without talking nonsense:
Application scenarios:
In business logic, messages, emails, logs, and so on are often sent. it is better to use asynchronization at this time. the user's direct experience is: the use of thieves is smooth ~~
Technology used:
1. gearman: This not only supports PHP but also other languages.
2. swoole: PHP extensions are available, making it easier to use
NOTE: gearman = swoole + asynchronous queue;
Differences:
1. gearman has a queue dedicated to storing asynchronous requests sent. even if the worker fails and restarts, it can still process unprocessed requests. swoole has no special processing at this point.
2. swoole is more convenient to use and install. it is easier to use PHP extensions written in C language. it has been tested in performance. so far, it is no problem to use it. gearman installation is troublesome. There are a lot of articles on the Internet, it was useless to try a lot. it was solved only on the official website of gearman.
3. gearman has a long history and has a wide range of application scenarios. It has detailed documents and is stable because of its low business volume. swoole is developed by Chinese people (supporting domestic production) and is used by many large companies,
Detailed gearman installation documents:
Yum-y install libgearmanyum install libgearman-develwget http://pecl.php.net/get/gearman-1.1.2.tgztar-zxvf gearman-1.1.2.tgzcd gearman-1.1.2/data/apps/php/bin/phpize. /configure -- prefix =/data/apps/phpgarman -- with-php-config =/data/apps/php/bin/php-configmake & make installvim/data/apps/php /etc/php. extension = gearman added to ini. so test vim worker. php
AddServer (); $ worker-> addFunction ("reverse", "my_reverse_function"); while ($ worker-> work (); function my_reverse_function ($ job) {return strrev ($ job-> workload () ;}?> Vim client. php
AddServer (); print $ client-> do ("reverse", "Hello World! ");?> Php client. php! DlroW olleH
Install swoole's PHP extension:
wget http://pecl.php.net/get/swoole-1.7.17.tgztar -zxvf swoole-1.7.17.tgzcd swoole-1.7.17phpize./configuremake && make install