Php asynchronous subuse improves user experience

Source: Internet
Author: User
Php asynchronous calls improve user experience. this is written by a friend of mine who has a good technology, I want to post on my blog so that php fans and friends who are interested in php learning can refer .??????? Case: In an SNS community in PHP, the user sends an email to his friends (hundreds of friends) in the system. the content of each email is different. after the email is sent, the prompt is sent! PHP Asynchronous call in common php to improve user experience

This is written by a good technical friend of mine. if you want to post it on my blog, you can get reference from php fans and friends who are interested in php learning.
??????? Case: PHP language
In an SNS community, users send emails to their friends (hundreds of friends) in the system. the content of each email is different. after sending the email, the system prompts that the email has been sent!
Common PHP writing
Sendmail. php

 

?
Assume that 100 emails are sent. What are the results of this operation?
User Experience: User waiting-> sending dozens of emails-> System timeout error message returned
This operation requires sending a large number of emails, resulting in php execution time being too long, and users are excited to wait. If apache or nginx waits for more than the allowed execution time, a timeout error is returned. At this time, the user does not know whether the operation was successful or not, and how many emails have been sent.
We can see that the user experience of this code is very poor and the task cannot be completed smoothly.
What should I do?
Here we mention the concept of asynchronous execution.
User Experience: User waiting-> sending completed
Friends will ask, why is there a lack of email sending?
OK. when the user submits a request, the Mail sending task is transferred to a php program that handles the Mail separately, when the user sees that "sending is complete", the real message has not been sent. at this time, the sender program is working hard in the background and sending one letter to the outside.
Sendmail. php

 System_mail.php
 

? After changing to the asynchronous mode, the user submits the information and can immediately get the result "sent ". The email will be sent in the background one by one until the email is sent.
This article from php enthusiasts http://www.phplover.cn/, the original address: http://www.phplover.cn/post/phpyibugongzuotishengyonghutiyan.html

?

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.