/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
- * Copyright (c) 2001-2012 *
+ * Copyright (c) 2001-2014 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
$url_cron = generer_url_action('cron','',false,true);
- // Si fsockopen est possible, on lance le cron via un socket
- // en asynchrone
- if(function_exists('fsockopen')){
- $parts=parse_url($url_cron);
-
- $fp = @fsockopen($parts['host'],
- isset($parts['port'])?$parts['port']:80,
- $errno, $errstr, 30);
-
- if ($fp) {
- $query = $parts['path'].($parts['query']?"?".$parts['query']:"");
- $out = "GET ".$query." HTTP/1.1\r\n";
- $out.= "Host: ".$parts['host']."\r\n";
- $out.= "Connection: Close\r\n\r\n";
- fwrite($fp, $out);
- fclose($fp);
+ if (!defined('_HTML_BG_CRON_FORCE') OR !_HTML_BG_CRON_FORCE){
+
+ // methode la plus rapide :
+ // Si fsockopen est possible, on lance le cron via un socket en asynchrone
+ // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
+ // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
+ // on passe direct a la methode background-image
+ if(function_exists('fsockopen')){
+ $parts=parse_url($url_cron);
+
+ switch ($parts['scheme']) {
+ case 'https':
+ $scheme = 'ssl://';
+ $port = 443;
+ break;
+ case 'http':
+ default:
+ $scheme = '';
+ $port = 80;
+ }
+
+ $fp = @fsockopen($scheme.$parts['host'],
+ isset($parts['port'])?$parts['port']:$port,
+ $errno, $errstr, 1);
+
+ if ($fp) {
+ $query = $parts['path'].($parts['query']?"?".$parts['query']:"");
+ $out = "GET ".$query." HTTP/1.1\r\n";
+ $out.= "Host: ".$parts['host']."\r\n";
+ $out.= "Connection: Close\r\n\r\n";
+ fwrite($fp, $out);
+ fclose($fp);
+ return $texte;
+ }
+ }
+ // si fsockopen n'est pas dispo on essaye cURL :
+ // lancer le cron par un cURL asynchrone si cURL est present
+ elseif (function_exists("curl_init")){
+ //setting the curl parameters.
+ $ch = curl_init($url_cron);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
+ curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
+ // valeur mini pour que la requete soit lancee
+ curl_setopt($ch, CURLOPT_TIMEOUT_MS, 100);
+ // lancer
+ curl_exec($ch);
+ // fermer
+ curl_close($ch);
return $texte;
}
}
- // ici lancer le cron par un CURL asynchrone si CURL est present
- if (function_exists("curl_init")){
- //setting the curl parameters.
- $ch = curl_init($url_cron);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
- curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
- // valeur mini pour que la requete soit lancee
- curl_setopt($ch, CURLOPT_TIMEOUT_MS, 100);
- // lancer
- curl_exec($ch);
- // fermer
- curl_close($ch);
- return $texte;
- }
-
// si deja force, on retourne sans rien
if (defined('_DIRECT_CRON_FORCE'))
return $texte;