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

藏色散人
Release: 2023-03-14 15:42:02
Original
4876 people have browsed it

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);
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template