X-Git-Url: http://git.cyclocoop.org/?p=lhc%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Fqueue.php;h=a99d43284e353440a280e10f3d3b92f8134799ca;hp=140efd8576c07aba3d1a705451db7ea501bb145e;hb=122c920eb07e3f665789f8734965b576e6c25515;hpb=226942065cd4f604eb464addf45a065c9e5bc916 diff --git a/www/ecrire/inc/queue.php b/www/ecrire/inc/queue.php index 140efd85..a99d4328 100644 --- a/www/ecrire/inc/queue.php +++ b/www/ecrire/inc/queue.php @@ -3,7 +3,7 @@ /***************************************************************************\ * 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. * @@ -475,7 +475,7 @@ function queue_set_next_job_time($next) { // permet ausis d'initialiser le nom de fichier a coup sur $curr_next = $_SERVER['REQUEST_TIME'] + queue_sleep_time_to_next_job(true); if ( - ($curr_next<$time AND $next>$time) // le prochain job est dans le futur mais pas la date planifiee actuelle + ($curr_next<=$time AND $next>$time) // le prochain job est dans le futur mais pas la date planifiee actuelle OR $curr_next>$next // le prochain job est plus tot que la date planifiee actuelle ) { if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) { @@ -514,42 +514,59 @@ function queue_affichage_cron(){ $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;