0

Im writing a php cron script that needs to run a url

After some database modifications the php script needs to execute an url

$url = 'http://server.domain.com/cronjob.php?idorder='.$orderid.'&idcustomer='.$idklant;
$fp = fopen(dirname(__FILE__).'/../data/errorlog.txt', 'w');

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
curl_setopt ($ch, CURLOPT_CONNECT_ONLY);
//curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
//curl_setopt ($ch, CURLOPT_AUTOREFERER, true);
//curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
// debug 
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
//
$exec = curl_exec($ch);
curl_close($ch);

echo $url.'<br>';

The error log shows * About to connect() to server.domain.com port 80 (#0)

  • Trying xxx.xxx.xxx.xxx... * Connection timed out
  • couldn't connect to host
  • Closing connection #0

But when I run the $url direct in a browser window it works

  • Are you able to visit the URL via web browser no problem? – MonkeyZeus Mar 09 '15 at 15:11
  • Something in your server setup prevents the connection to this URL. Most likely it is the firewall. It could also be something in the way the network is set up. More information on the provider and its network is needed to judge if the reason is there. – Tero Kilkanen Mar 09 '15 at 16:07
  • indeed It was the network, apparently connecting form the internal lan to public was forbidden. Changing the code to: $url = 'http://'.$_SERVER['SERVER_NAME'].' solved the problem. – Erestor Elensar Mar 10 '15 at 07:16

0 Answers0