PHP asynchronous operations (swoole, gearman)-php Tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.