Since a while, I'm getting the following error "connection reset by peer" on any cURL connection that try to connect to its same domain.
Because the execution time limit of PHP, I separate the code into a numer of php scripts, and I call them secuentially semaphores implemented using a common mySQL database and cURL to call the appropiate script. Using cron I lunch the process every 10min and if every thing is done, it end. Otherwise, i calls via cuRL the appropiate script.
I have other scripts on the same domain that make cURL calls to scripts on sites outside my x10 domain, and thy work fine, but when calling the local scripts php makes NOTHING and gives NONE error status.
I also have try to use Snoopy to test the calls, but the same happends: OK on calls to outside domains, nothing happens on calls on the same domain.
Can anybody send me a clue to get the things working again?
Here a test script :
Because the execution time limit of PHP, I separate the code into a numer of php scripts, and I call them secuentially semaphores implemented using a common mySQL database and cURL to call the appropiate script. Using cron I lunch the process every 10min and if every thing is done, it end. Otherwise, i calls via cuRL the appropiate script.
I have other scripts on the same domain that make cURL calls to scripts on sites outside my x10 domain, and thy work fine, but when calling the local scripts php makes NOTHING and gives NONE error status.
I also have try to use Snoopy to test the calls, but the same happends: OK on calls to outside domains, nothing happens on calls on the same domain.
Can anybody send me a clue to get the things working again?
Here a test script :
Code:
<?php
function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); }
$time_start = microtime_float();
$startupDir = defineStartupDir();
include_once($startupDir."/../include/classes/debug/log.class.php");
include_once($startupDir."/../include/classes/parser/Snoopy.class.php");
$ini_array = parse_ini_file($startupDir."/../include/config.ini",true);
$logFile = $ini_array["debug"]["BASE_DIR"].$ini_array["debug"]["LOG_DIR"].'/backoffice_acciones/_testSnoopy.log';
echo "LOG_DIR=(".$logFile.")<br>\n\r";
$log = new Log($logFile,$ini_array["debug"]["MESSAGES"]);
$log->setMode($ini_array["debug"]["MESSAGES"]);
$urlAnalisis = "http://".$_SERVER['HTTP_HOST']."/stocks/backoffice_stocks/analisisIN.php";
$url[] = $urlAnalisis;
foreach($url as $item) {
snoopyURLs($item);
}
foreach($url as $item) {
test_cURL($item);
}
/* ********** ********** */
function snoopyURLs($url) {
global $log,$ini_array;
// set browser and referer:
$snoopy = new Snoopy();
$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$snoopy->referer = "http://www.jonasjohn.de/";
// set some internal variables:
$snoopy->maxredirs = 2;
$snoopy->offsiteok = false;
$snoopy->expandlinks = false;
echo "<br>processURLs: Snoopy: <a href='".$url."' target='_new'>".$url."</a><br>";
if(!$snoopy->fetch($url)) { //Error al leer la pag web.
echo "processURLs: Snoopy->fetch: ERROR<br>";
} else {
echo "processURLs: Snoopy->fetch: OK<br>";
}
echo "processURLs: Snoopy->fetch: status:(".$snoopy->status.") error:(".$snoopy->error.") results:(".$snoopy->results.")<br>";
if(!$snoopy->submit($url)) {
echo "processURLs: Snoopy->submit: ERROR<br>";
} else {
echo "processURLs: Snoopy->submit: OK<br>";
}
echo "processURLs: Snoopy->submit: status:(".$snoopy->status.") error:(".$snoopy->error.") results:(".$snoopy->results.")<br>";
}
function test_cURL($url) {
global $log;
echo "<br>test_cURL: Snoopy: <a href='".$url."' target='_new'>".$url."</a><br>";
$ch = curl_init(); // create cURL handle (ch)
if (!$ch) {
$log->append("test_cURL: Couldn't initialize a cURL handle",'');
return;
}
// set some cURL options
$ret = curl_setopt($ch, CURLOPT_URL, $url);
$ret = curl_setopt($ch, CURLOPT_HEADER, 1);
$ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$ret = curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$ret = curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
$ret = curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
// execute
$ret = curl_exec($ch);
if (empty($ret)) {
// some kind of an error happened
$log->append("test_cURL: ERROR",curl_error($ch));
echo "test_cURL: ERROR: ".curl_error($ch)."<br>";
curl_close($ch); // close cURL handler
} else {
$info = curl_getinfo($ch);
$log->append("test_cURL: OK: curl_getinfo",$info);
curl_close($ch); // close cURL handler
if (empty($info['http_code'])) {
die("No HTTP code was returned");
} else {
// load the HTTP codes
$http_codes = parse_ini_file("path/to/the/ini/file/I/pasted/above");
// echo results
echo "The server responded: <br />";
echo $info['http_code'] . " " . $http_codes[$info['http_code']];
}
}
}
echo "OK (".$param[nemo].") fecha(".$param[fecha].") elapsed time: ".(microtime_float() - $time_start)." seg.";
$log->append("OK Indicador(".$param[nemo].") fecha(".$param[fecha].") elapsed time: ".(microtime_float() - $time_start)." seg.","");
?>
Last edited by a moderator: