[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / action / super_cron.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 /**
16 * Url pour lancer le cron de manière asynchrone si le serveur
17 * le permet
18 *
19 * On se base sur le même code que celui du pipeline affichage final
20 *
21 * Cette fonction est utile pour être appelée depuis un cron UNIX par exemple
22 * car elle retourne tout de suite
23 *
24 * Exemple de tache cron Unix pour un appel toutes les minutes :
25 * "* * * * * curl http://www.mondomaine.tld/spip.php?action=super_cron"
26 */
27 function action_super_cron_dist(){
28 // Si fsockopen est possible, on lance le cron via un socket
29 // en asynchrone
30 if(function_exists('fsockopen')){
31 $url = generer_url_action('cron');
32 $parts=parse_url($url);
33 $fp = fsockopen($parts['host'],
34 isset($parts['port'])?$parts['port']:80,
35 $errno, $errstr, 30);
36 if ($fp) {
37 $out = "GET ".$parts['path']."?".$parts['query']." HTTP/1.1\r\n";
38 $out.= "Host: ".$parts['host']."\r\n";
39 $out.= "Connection: Close\r\n\r\n";
40 fwrite($fp, $out);
41 fclose($fp);
42 return;
43 }
44 }
45 // ici lancer le cron par un CURL asynchrone si CURL est présent
46 // TBD
47
48 return;
49 }
50 ?>