![]() $httpCode = curl_getinfo($c, CURLINFO_HTTP_CODE) #checks http status If(curl_errno($c)) file_put_contents($errorsFile, "CURL_ERRNO: ".curl_errno($c)." (ID: ".$this->requestID.")\n", FILE_APPEND) $errorsFile = $this->folders.$this->folders.$this->files Here's the error log code #check for errors I should probably also mention that sometimes (about 1/8 of all requests) the requests "work", so it fulfils the purpose of this script but it still logs this kind of errors. $c = curl_init() Ĭurl_setopt($c, CURLOPT_URL, $this->url) Ĭurl_setopt($c, CURLOPT_PROXY, $this->proxy) Ĭurl_setopt($c, CURLOPT_USERAGENT, $this->browser) Ĭurl_setopt($c, CURLOPT_POSTFIELDS, $requestData) Ĭurl_setopt($c, CURLOPT_RETURNTRANSFER, true) Ĭurl_setopt($c, CURLOPT_FOLLOWLOCATION, 1) Īs you can see, they're all 2xx and 4xx and I've no idea why this is so. In order to dig further, the option CURLOPT_VERBOSE might help you to have extra information about the request behavior through the STDERR.I'm trying to send a cURL request through a proxy in PHP. In any case the reply to your question why your request does not get an error, I guess that the use of the option CURLOPT_NOSIGNAL and the different timeout options explained in the set_opt php manual might get you closer to it. Once you have the header with the code you are interested, you could run a php script that echoes the curl response and parse it by yourself: false, In this stackoverflow question CURLOPT_RETURNTRANSFER set to true doesnt work on hosting server, you can see that that the option CURLOPT_RETURNTRANSFER is directly affected by the requested host web server implementation.Īs you are using explicitly the response body, and your code relies on the response headers, a good way to solve this might be to: CURLOPT_RETURNTRANSFER => falseĪnd execute the curl code to work on the response headers. The server might not give a successful reply or, at least, a successful reply within the timeframe that curl has to receive the response and cache it, so the results are returned by the curl into the variable you assign. My experience working with curl showed me that sometimes when using the option: CURLOPT_RETURNTRANSFER => true I'll now follow suggestions given on this site for that kind of failure. So, I have found the why – thank you – and apparently was right and it is a network problem. (using code from this answer) and found the following in $curl_log when an URL failed (URL and IP changed): * About to connect() to port 80 (#0) So apparently the slowness of the failing URL is not a problem in itself for cURL.įollowing suggestion in his answer, I used: CURLOPT_VERBOSE => 1, cURL does not time out either, because when I try to connect to an URL with a script sleeping for 59 seconds, cURL successfully connects. ![]() Even when one of the URLs fails, the other connections are successfully made. ![]() In this time it connects to 300+ URLs successfully. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |