I have a PHP Curl function that is used for various queries in an application. Usually this function is used to communicate / start requests on other servers on the same computer (localhost). Function below: -
/** * @desc If a curl_multi handle is passed, a new curl * instance is added to the handle and the curl id is returned as string. * @param string $theServer * @param string $thePath * @param number $thePort * @param curl_multi $mcHandle * @return string|curl_handle */ function sendPOSTtoURL($theServer, $thePath, $theData, $thePort = 80, $mcHandle = null) { global $bDebug; $theResult = ""; //$bDebug = true; $cPost = curl_init(); if ($cPost !== false) { curl_setopt($cPost, CURLOPT_URL, "http://".$theServer.$thePath); if ($thePort != 80) curl_setopt($cPost, CURLOPT_PORT, $thePort); // Set port if different from 80 curl_setopt($cPost, CURLOPT_HEADER, false); curl_setopt($cPost, CURLOPT_FORBID_REUSE, true); curl_setopt($cPost, CURLOPT_FRESH_CONNECT, true); curl_setopt ($cPost, CURLOPT_POST, true); curl_setopt ($cPost, CURLOPT_POSTFIELDS, $theData); curl_setopt ($cPost, CURLOPT_RETURNTRANSFER, true); $returndata = curl_exec ($cPost); if ($mcHandle == null) { if (! $theResult = curl_exec($cPost)) { if (curl_errno($cPost) > 0) { $theResult = CURL_ERROR; if ($bDebug) $theResult .= fcURLError($cPost); } else { $theResult = CURL_NOERR_NOINFO; if ($bDebug) $theResult .= fcURLError($cPost); } } curl_close($cPost); return $theResult; } else { curl_multi_add_handle($mcHandle, $cPost); return $cPost; } } else return CURL_INIT_FAIL; }
I will not go into complexity, but it is intended to return text if it is the only request or the curl handle is added if the multi_curl handle is passed.
The problem is that when I request it to perform a task on a remote server, it performs a double request. We have a setting in which the requesting server connects to the remote server via VPN and can fulfill requests to the external Internet through it. I thought the target server starts it twice, so I made a call (to send email) from the calling server as follows: -
$aEmail = array("email_address" => $sEmailAddress, "email_subject" => $sEmailSubject, "email_body" => $sEmailBody); echo sendPOSTtoURL("<REMOTE IP HERE", "/emailService/doMail.php?rand=".mt_rand(), $aEmail);
calling mt_rand generates a random number, so I can identify each request. This is what I got on the remote server: -
<CALLING IP> - - [15/Jun/2011:20:39:57 +0500] "POST /emailService/doMail.php?rand=1551627310 HTTP/1.1" 200 1060 "-" "-" <CALLING IP> - - [15/Jun/2011:20:40:01 +0500] "POST /emailService/doMail.php?rand=1551627310 HTTP/1.1" 200 1060 "-" "-"
As you can see, the same request comes in twice. and what do you think is going on? right, 2 letters to the goal! I cannot (due to managerial [S @ # $] reasons) develop logic to handle this on a remote server.