Home >Backend Development >PHP Problem >How to solve the problem of php curl request failure

How to solve the problem of php curl request failure

藏色散人
藏色散人Original
2021-12-27 09:52:304872browse

php Solution to curl request failure: 1. Open the corresponding PHP file; 2. Set "curl_setopt($ch, CURLOPT_FORBID_REUSE, 1)...".

How to solve the problem of php curl request failure

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn