Home >Backend Development >PHP Problem >How to solve the problem of php curl request failure
php Solution to curl request failure: 1. Open the corresponding PHP file; 2. Set "curl_setopt($ch, CURLOPT_FORBID_REUSE, 1)...".
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to solve the problem of php curl request failure?
php curl send request failure problem
Prerequisite: run on the command line In mode (no timeout setting)
If curl is called multiple times, the request may fail to be sent. The reason may be that curl connection is reused and is created in the cache pool.
Solution: Set curl parameters,
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
Reference link: https://www.php.net/manual/zh/function.curl-setopt.php
An exception is a reference case:
if you would like to send xml request to a server (lets say, making a soap proxy), you have to set <?php curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); ?> makesure you watch for cache issue: the below code will prevent cache... <?php curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve the problem of php curl request failure. For more information, please follow other related articles on the PHP Chinese website!