843df551bc6a001aed74d67259174231690fd23c
[lhc/web/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-2017 *
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 /**
14 * Action pour exécuter le cron de manière asynchrone si le serveur le permet
15 *
16 * @package SPIP\Core\Genie
17 */
18
19 if (!defined('_ECRIRE_INC_VERSION')) {
20 return;
21 }
22
23 /**
24 * Url pour lancer le cron de manière asynchrone si le serveur le permet
25 *
26 * Cette fonction est utile pour être appelée depuis un cron UNIX par exemple
27 * car elle se termine tout de suite
28 *
29 * Exemple de tache cron Unix pour un appel toutes les minutes :
30 * `* * * * * curl http://www.mondomaine.tld/spip.php?action=super_cron`
31 *
32 * @see queue_affichage_cron() Dont une partie du code est repris ici.
33 * @see action_cron() URL appelée en asynchrone pour excécuter le cron
34 */
35 function action_super_cron_dist() {
36 // Si fsockopen est possible, on lance le cron via un socket
37 // en asynchrone
38 if (function_exists('fsockopen')) {
39 $url = generer_url_action('cron');
40 $parts = parse_url($url);
41 $fp = fsockopen($parts['host'],
42 isset($parts['port']) ? $parts['port'] : 80,
43 $errno, $errstr, 30);
44 if ($fp) {
45 $out = "GET " . $parts['path'] . "?" . $parts['query'] . " HTTP/1.1\r\n";
46 $out .= "Host: " . $parts['host'] . "\r\n";
47 $out .= "Connection: Close\r\n\r\n";
48 fwrite($fp, $out);
49 fclose($fp);
50
51 return;
52 }
53 }
54 // ici lancer le cron par un CURL asynchrone si CURL est présent
55 // TBD
56
57 return;
58 }