Php interface problems

Source: Internet
Author: User
When the connection interface is slow, the request times out. how can this problem be solved? When the connection interface is slow, the request times out. how can this problem be solved?

Reply content:

When the connection interface is slow, the request times out. how can this problem be solved?

Exception capture.

Recommended class library GuzzleHttp: http://docs.guzzlephp.org/en...

400/500 errors can be captured and processed by yourself.

The network speed is slow and there is no solution. the interface logic can only be optimized as much as possible and timeout processing can be done well.

Initiate a request again based on the returned timeout status. the request has ended more than the specified number of times.

Slow network speed:

  • Slow user? Prompt network is not good. please try again later

  • Slow service? Add bandwidth

Added the timeout setting for curl. if the interface returns an error, run it again.
If the interface does not need to be returned in time, use the queue for processing.
curl_setopt($ch, CURLOPT_TIMEOUT, 600);

// Timeout in milliseconds if the record url times out to log $ timeout_ms = 1000; curl_setopt ($ ch, CURLOPT_TIMEOUT, $ timeout_ms );

If it is a network problem, try modifying the direct interface address of the host file.
If it is a code problem, try to optimize the code,
In addition, it is necessary to set the timeout time reasonably.

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.