cURL error 56 connection reset by peer

Status
Not open for further replies.

pabella

New Member
Messages
22
Reaction score
0
Points
1
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 :

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:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
My guess is that they have configured the Firewall to refuse connections from the same server.
 

pabella

New Member
Messages
22
Reaction score
0
Points
1
Could be, I also have that as 1 of the causes, but how can I check it to be sure?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I tested it on an account on the server Vox. It had that error when it tried to call a page on the site. It had that error when it tried to call another site on Vox.
It did not have an error when it called a site on Absolut
 

pabella

New Member
Messages
22
Reaction score
0
Points
1
Well, my site is located on ABSOLUT, and 'cause I'm inChile, I can not create another site to test.
I don't know sites on other hosts to make some tests, but it would be fine if some administrator o anybody who knows about the firewall configuration could add some information.
best regards, hope we can get some info from X10hostng soon.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
I'm consulting with another staff member about this. Please hold on.
 

pabella

New Member
Messages
22
Reaction score
0
Points
1
So, any clue about the firewall setup that prevents calls to the same server?
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Sorry, I meant to get back to you about this.

The firewall is not to blame for this issue. It must be an issue with your script.
 

pabella

New Member
Messages
22
Reaction score
0
Points
1
I tested it on an account on the server Vox. It had that error when it tried to call a page on the site. It had that error when it tried to call another site on Vox.
It did not have an error when it called a site on Absolut
#descalzo: Hi, just to check:
have you use the same script as me to test the cURL call, or doo you wote another script?
I make that cuestion because #leafypiggy says the firewall is not to blame an the problem could be on the script, but as I see, the script is OK!
 

pabella

New Member
Messages
22
Reaction score
0
Points
1
OK. I made a little test in order to check again why the calls to the same server where the calling script is did not work.
Here is my script (both located on the roor directory of my free hosting account):
<?php // hello_world.php
echo "Hello World<br>";
?>

This script should call using cURL the previous one.
<?php // test_curl.php
$url = "http://www.mydomain.com"."/hello_world.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
$status = curl_exec($ch);
echo "curl_errno: ".curl_errno($ch)."<br>";
curl_close($ch);
?>

When calling the "test_curl.php" script it gives me a CURLE_RECV_ERROR (56) code, which means "Failure with receiving network data."
Is there anybody who could check this and give me some clue to make cURL work on calls to the same domain?
 

pabella

New Member
Messages
22
Reaction score
0
Points
1
I continue testing the script, and the error description gives this message: "Failed to connect to 69.175.6.102: Network is unreachable"
When I try to check that address, it points to: placeholder.x10hosting.com
Maybe thats the problem. placeholder.x10hosting.com is not my domain, soo my script could not be found.
Is there some way to avoid that "domain translation" problem?
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Annnnndd I found the user that's been causing outbound DoS attacks from absolut to placeholder...
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
(don't worry, I'm *pretty* sure it's not your fault)
 

pabella

New Member
Messages
22
Reaction score
0
Points
1
Sorry for that. I was not my intention.
But I thing there is somebody else causing that attacks:
the "Failed to connect to 69.175.6.102: Network is unreachable" message only appears if I omit the domain in the cURL call (I have done it only to test).
Ex.: instead of forming the URL as "http://mydomain.com/test_curl.php" I put only "hello_world.php" in the test_curl.php script
 
Status
Not open for further replies.
Top