Inconsistent cURL connection

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Inconsistent cURL connection

Post by John Cartwright »

I've developed a hit/signup tracking component for a few websites, however, for severals hours during the day (at random times and lengths), any cURL call made to the tracking website fails because a connection cannot be made. After awhile, the tracking will begin to work again. It is also worth noting sender websites and the recipient website to the curl call are both on seperate servers.

Below I have attached the code which makes the cURL call as well as a snippet of the log files. In the logs files you can see several examples of successful posts being made, however at the bottom the connection begins to fail.

Instinctively, during the outtages I would have the script below output the request string to test the string manually (by entering the url and params into the address bar) and the recipient server would process the request correctly. The website itself will never goes down and has consistently low loads (even during peak traffic and the said curl outtages).

So my questions are:

1. What could the possible causes be?
2. What is the most reliable way to send requests to restful API's?

Code: Select all

if (!empty($_GET['t']) && empty($_SESSION['camaff_tracking_click_id'])) {
    $requeststr = 'account_id='. (int)$_GET['t'];
    $requeststr.= '&endpage_id=1';
    $requeststr.= '&ip='. $_SERVER['REMOTE_ADDR'];
 
    $fp = fopen(dirname(__FILE__).'/logs/errorlog.txt', 'a'); 
 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://imcash.biz/tracking/traffic');
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_STDERR, $fp); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $requeststr);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $result = curl_exec($ch);   
    curl_close($ch);    
    
    $_SESSION['camaff_tracking_click_id'] = (int)$result;
}

Code: Select all

< HTTP/1.1 200 OK
< Date: Tue, 17 Feb 2009 18:12:07 GMT
< Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8b mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8
< X-Powered-By: PHP/5.2.8
< Set-Cookie: CAKEPHP=4e2833e89a670f12701dcb04b6b78722; expires=Sat, 18 Feb 2034 00:12:07 GMT; path=/
< P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
< Content-Length: 0
< Content-Type: text/html
< 
* Connection #0 to host imcash.biz left intact
* Closing connection #0
* About to connect() to imcash.biz port 80 (#0)
*   Trying 213.175.206.155... * connected
* Connected to imcash.biz (213.175.206.155) port 80 (#0)
> POST /tracking/traffic HTTP/1.1
Host: imcash.biz
Accept: */*
Content-Length: 42
Content-Type: application/x-www-form-urlencoded
 
< HTTP/1.1 200 OK
< Date: Tue, 17 Feb 2009 18:24:55 GMT
< Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8b mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8
< X-Powered-By: PHP/5.2.8
< Set-Cookie: CAKEPHP=42c8a9217e48076577def3b1cee14640; expires=Sat, 18 Feb 2034 00:24:55 GMT; path=/
< P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
< Content-Length: 0
< Content-Type: text/html
< 
* Connection #0 to host imcash.biz left intact
* Closing connection #0
* About to connect() to imcash.biz port 80 (#0)
*   Trying 213.175.206.155... * connected
* Connected to imcash.biz (213.175.206.155) port 80 (#0)
> POST /tracking/traffic HTTP/1.1
Host: imcash.biz
Accept: */*
Content-Length: 42
Content-Type: application/x-www-form-urlencoded
 
< HTTP/1.1 200 OK
< Date: Tue, 17 Feb 2009 19:12:45 GMT
< Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8b mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8
< X-Powered-By: PHP/5.2.8
< Set-Cookie: CAKEPHP=2e8cffcdfc02568bd2c5a108d122bbe4; expires=Sat, 18 Feb 2034 01:12:45 GMT; path=/
< P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
< Content-Length: 0
< Content-Type: text/html
< 
* Connection #0 to host imcash.biz left intact
* Closing connection #0
* About to connect() to imcash.biz port 80 (#0)
*   Trying 213.175.206.155... * connected
* Connected to imcash.biz (213.175.206.155) port 80 (#0)
> POST /tracking/traffic HTTP/1.1
Host: imcash.biz
Accept: */*
Content-Length: 42
Content-Type: application/x-www-form-urlencoded
 
< HTTP/1.1 200 OK
< Date: Tue, 17 Feb 2009 19:21:03 GMT
< Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8b mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8
< X-Powered-By: PHP/5.2.8
< Set-Cookie: CAKEPHP=6d19dc65822fd8df68778715d0cf0b20; expires=Sat, 18 Feb 2034 01:21:03 GMT; path=/
< P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
< Content-Length: 0
< Content-Type: text/html
< 
* Connection #0 to host imcash.biz left intact
* Closing connection #0
* About to connect() to imcash.biz port 80 (#0)
*   Trying 213.175.206.155... * connected
* Connected to imcash.biz (213.175.206.155) port 80 (#0)
> POST /tracking/traffic HTTP/1.1
Host: imcash.biz
Accept: */*
Content-Length: 42
Content-Type: application/x-www-form-urlencoded
 
< HTTP/1.1 200 OK
< Date: Tue, 17 Feb 2009 19:55:43 GMT
< Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8b mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8
< X-Powered-By: PHP/5.2.8
< Set-Cookie: CAKEPHP=d22b44e4a9c424a2df0b43766d3355f7; expires=Sat, 18 Feb 2034 01:55:43 GMT; path=/
< P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
< Content-Length: 0
< Content-Type: text/html
< 
* Connection #0 to host imcash.biz left intact
* Closing connection #0
* getaddrinfo(3) failed for imcash.biz:80
* Couldn't resolve host 'imcash.biz'
* Closing connection #0
* getaddrinfo(3) failed for imcash.biz:80
* Couldn't resolve host 'imcash.biz'
* Closing connection #0
 
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Inconsistent cURL connection

Post by VladSun »

# getaddrinfo(3) failed for imcash.biz:80
# * Couldn't resolve host 'imcash.biz'
# * Closing connection #0
Looks like a DNS problem. Check if the DNS serving imcash.biz is online and responding during these outages.
Instinctively, during the outtages I would have the script below output the request string to test the string manually (by entering the url and params into the address bar) and the recipient server would process the request correctly.
I still think it's a DNS problem, because you might have used cached DNS data, which is not available to cURL.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Inconsistent cURL connection

Post by John Cartwright »

Turns out the host had misconfigured some DNS options on our box. The nameservers were subsequently changed to the correct ones (ns1.imcash.biz, ns2.imcash.biz) so hopefully this will have resolved the issue. Only time (and log files) will tell!

As usual, thanks a bunch VladSun.
Post Reply