php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50553 Multiple curl_exec and curl_close looses host
Submitted: 2009-12-22 08:00 UTC Modified: 2009-12-22 10:43 UTC
From: levi_tedder at hotmail dot com Assigned:
Status: Not a bug Package: cURL related
PHP Version: 5.2.12 OS: Windows XP, Windows 2003
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: levi_tedder at hotmail dot com
New email:
PHP Version: OS:

 

 [2009-12-22 08:00 UTC] levi_tedder at hotmail dot com
Description:
------------
If you have a web server host that responds very quickly and you're doing a lot of requests on it, curl will eventually respond "couldn't connect to host". This happens on my Windows XP machine and Windows 2003 server, but I've been unable to reproduce on Windows 2008. If I add a delay with usleep(50000) it seems to be ok.
I'm not sure if this is by design, OS-restriction or wrong usage (I've tried forums) or actual bug. Please forgive misplacement.

To get the script below to exit with "couldn't connect to host" you need a fast responding web server host. 

Reproduce code:
---------------
<?php

$url = "http://www.example.com";

for ($i = 1; $i <= 6000; $i++) {

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $result=curl_exec ($ch);

    if (curl_errno($ch)) {
        exit(curl_error($ch));
    } else {
        curl_close($ch);
        echo "count: $i\n";
    }
}
?> 

Expected result:
----------------
count: 1
.
.
count: 6000

Actual result:
--------------
count: 1
.
.
count 4322
couldn't connect to host

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-22 08:58 UTC] jani@php.net
Whatever is happening happens in curl, so ask support there, not here. But basically what you're doing: Just DO NOT do that. If you need to do that, you're either doing something nasty or don't really know what you're doing. 
 [2009-12-22 10:43 UTC] levi_tedder at hotmail dot com
What are you talking about? Where is "there"? I'm using PHP and post a thing here.
I'm doing what I'm doing because there's a service running on a server that needs to be contacted this way (a http get request).
If I have a lot of simultaneous heavy usage (which is extremely common), the example script below will show what happens. Why wouldn't I do this then?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 09:01:29 2024 UTC