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