@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $md5args = md5($arguments); |
| 71 | 71 | |
| 72 | 72 | // si pas de date programee, des que possible |
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 73 | + $duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND '; |
|
| 74 | 74 | if (!$time) { |
| 75 | 75 | $time = time(); |
| 76 | 76 | $duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution |
@@ -94,9 +94,8 @@ discard block |
||
| 94 | 94 | and |
| 95 | 95 | $id_job = sql_getfetsel('id_job', 'spip_jobs', |
| 96 | 96 | $duplicate_where = |
| 97 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))) |
|
| 97 | + $duplicate_where.'fonction='.sql_quote($function) |
|
| 98 | + . (($no_duplicate === 'function_only') ? '' : ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file))) |
|
| 100 | 99 | ) { |
| 101 | 100 | return $id_job; |
| 102 | 101 | } |
@@ -108,9 +107,9 @@ discard block |
||
| 108 | 107 | if ( |
| 109 | 108 | $no_duplicate |
| 110 | 109 | and |
| 111 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<" . intval($id_job) . " AND $duplicate_where") |
|
| 110 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<".intval($id_job)." AND $duplicate_where") |
|
| 112 | 111 | ) { |
| 113 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 112 | + sql_delete('spip_jobs', 'id_job='.intval($id_job)); |
|
| 114 | 113 | |
| 115 | 114 | return $id_prev; |
| 116 | 115 | } |
@@ -122,9 +121,9 @@ discard block |
||
| 122 | 121 | // ie cas d'un char non acceptables sur certains type de champs |
| 123 | 122 | // qui coupe la valeur |
| 124 | 123 | if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
| 125 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 124 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job)); |
|
| 126 | 125 | if ($args !== $arguments) { |
| 127 | - spip_log('arguments job errones / longueur ' . strlen($args) . " vs " . strlen($arguments) . ' / valeur : ' . var_export($arguments, |
|
| 126 | + spip_log('arguments job errones / longueur '.strlen($args)." vs ".strlen($arguments).' / valeur : '.var_export($arguments, |
|
| 128 | 127 | true), 'queue'); |
| 129 | 128 | } |
| 130 | 129 | } |
@@ -152,7 +151,7 @@ discard block |
||
| 152 | 151 | function queue_purger() { |
| 153 | 152 | include_spip('base/abstract_sql'); |
| 154 | 153 | sql_delete('spip_jobs'); |
| 155 | - sql_delete("spip_jobs_liens", "id_job NOT IN (" . sql_get_select("id_job", "spip_jobs") . ")"); |
|
| 154 | + sql_delete("spip_jobs_liens", "id_job NOT IN (".sql_get_select("id_job", "spip_jobs").")"); |
|
| 156 | 155 | include_spip('inc/genie'); |
| 157 | 156 | genie_queue_watch_dist(); |
| 158 | 157 | } |
@@ -167,8 +166,8 @@ discard block |
||
| 167 | 166 | function queue_remove_job($id_job) { |
| 168 | 167 | include_spip('base/abstract_sql'); |
| 169 | 168 | |
| 170 | - if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 171 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 169 | + if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job='.intval($id_job)) |
|
| 170 | + and $res = sql_delete('spip_jobs', 'id_job='.intval($id_job)) |
|
| 172 | 171 | ) { |
| 173 | 172 | queue_unlink_job($id_job); |
| 174 | 173 | // est-ce une tache cron qu'il faut relancer ? |
@@ -217,7 +216,7 @@ discard block |
||
| 217 | 216 | * resultat du sql_delete |
| 218 | 217 | */ |
| 219 | 218 | function queue_unlink_job($id_job) { |
| 220 | - return sql_delete("spip_jobs_liens", "id_job=" . intval($id_job)); |
|
| 219 | + return sql_delete("spip_jobs_liens", "id_job=".intval($id_job)); |
|
| 221 | 220 | } |
| 222 | 221 | |
| 223 | 222 | /** |
@@ -233,7 +232,7 @@ discard block |
||
| 233 | 232 | // deserialiser les arguments |
| 234 | 233 | $args = unserialize($row['args']); |
| 235 | 234 | if ($args === false) { |
| 236 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 235 | + spip_log('arguments job errones '.var_export($row, true), 'queue'); |
|
| 237 | 236 | $args = array(); |
| 238 | 237 | } |
| 239 | 238 | |
@@ -250,12 +249,12 @@ discard block |
||
| 250 | 249 | } |
| 251 | 250 | |
| 252 | 251 | if (!function_exists($fonction)) { |
| 253 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 252 | + spip_log("fonction $fonction ($inclure) inexistante ".var_export($row, true), 'queue'); |
|
| 254 | 253 | |
| 255 | 254 | return false; |
| 256 | 255 | } |
| 257 | 256 | |
| 258 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 257 | + spip_log("queue [".$row['id_job']."]: $fonction() start", 'queue'); |
|
| 259 | 258 | switch (count($args)) { |
| 260 | 259 | case 0: |
| 261 | 260 | $res = $fonction(); |
@@ -295,7 +294,7 @@ discard block |
||
| 295 | 294 | # plus lent mais completement generique |
| 296 | 295 | $res = call_user_func_array($fonction, $args); |
| 297 | 296 | } |
| 298 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 297 | + spip_log("queue [".$row['id_job']."]: $fonction() end", 'queue'); |
|
| 299 | 298 | |
| 300 | 299 | return $res; |
| 301 | 300 | |
@@ -327,14 +326,14 @@ discard block |
||
| 327 | 326 | function queue_schedule($force_jobs = null) { |
| 328 | 327 | $time = time(); |
| 329 | 328 | if (defined('_DEBUG_BLOCK_QUEUE')) { |
| 330 | - spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq' . _LOG_DEBUG); |
|
| 329 | + spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq'._LOG_DEBUG); |
|
| 331 | 330 | |
| 332 | 331 | return; |
| 333 | 332 | } |
| 334 | 333 | |
| 335 | 334 | // rien a faire si le prochain job est encore dans le futur |
| 336 | 335 | if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
| 337 | - spip_log("queue_sleep_time_to_next_job", 'jq' . _LOG_DEBUG); |
|
| 336 | + spip_log("queue_sleep_time_to_next_job", 'jq'._LOG_DEBUG); |
|
| 338 | 337 | |
| 339 | 338 | return; |
| 340 | 339 | } |
@@ -355,7 +354,7 @@ discard block |
||
| 355 | 354 | } |
| 356 | 355 | $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
| 357 | 356 | |
| 358 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 357 | + spip_log("JQ schedule $time / $end_time", 'jq'._LOG_DEBUG); |
|
| 359 | 358 | |
| 360 | 359 | if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
| 361 | 360 | define('_JQ_MAX_JOBS_EXECUTE', 200); |
@@ -369,19 +368,19 @@ discard block |
||
| 369 | 368 | // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
| 370 | 369 | // pour qu'il ne bloque pas les autres jobs en attente |
| 371 | 370 | if (is_array($force_jobs) and count($force_jobs)) { |
| 372 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND " . sql_in("id_job", $force_jobs); |
|
| 371 | + $cond = "status=".intval(_JQ_SCHEDULED)." AND ".sql_in("id_job", $force_jobs); |
|
| 373 | 372 | } else { |
| 374 | 373 | $now = date('Y-m-d H:i:s', $time); |
| 375 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND date<=" . sql_quote($now); |
|
| 374 | + $cond = "status=".intval(_JQ_SCHEDULED)." AND date<=".sql_quote($now); |
|
| 376 | 375 | } |
| 377 | 376 | |
| 378 | 377 | register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
| 379 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 378 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,'.(_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 380 | 379 | do { |
| 381 | 380 | if ($row = array_shift($res)) { |
| 382 | 381 | $nbj++; |
| 383 | 382 | // il faut un verrou, a base de sql_delete |
| 384 | - if (sql_delete('spip_jobs', "id_job=" . intval($row['id_job']) . " AND status=" . intval(_JQ_SCHEDULED))) { |
|
| 383 | + if (sql_delete('spip_jobs', "id_job=".intval($row['id_job'])." AND status=".intval(_JQ_SCHEDULED))) { |
|
| 385 | 384 | #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
| 386 | 385 | // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
| 387 | 386 | $row['status'] = _JQ_PENDING; |
@@ -396,13 +395,13 @@ discard block |
||
| 396 | 395 | queue_close_job($row, $time, $result); |
| 397 | 396 | } |
| 398 | 397 | } |
| 399 | - spip_log("JQ schedule job end time " . $time, 'jq' . _LOG_DEBUG); |
|
| 398 | + spip_log("JQ schedule job end time ".$time, 'jq'._LOG_DEBUG); |
|
| 400 | 399 | } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
| 401 | - spip_log("JQ schedule end time " . time(), 'jq' . _LOG_DEBUG); |
|
| 400 | + spip_log("JQ schedule end time ".time(), 'jq'._LOG_DEBUG); |
|
| 402 | 401 | |
| 403 | 402 | if ($row = array_shift($res)) { |
| 404 | 403 | queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
| 405 | - spip_log("JQ encore !", 'jq' . _LOG_DEBUG); |
|
| 404 | + spip_log("JQ encore !", 'jq'._LOG_DEBUG); |
|
| 406 | 405 | } else { |
| 407 | 406 | queue_update_next_job_time(); |
| 408 | 407 | } |
@@ -438,9 +437,9 @@ discard block |
||
| 438 | 437 | } |
| 439 | 438 | } |
| 440 | 439 | // purger ses liens eventuels avec des objets |
| 441 | - sql_delete("spip_jobs_liens", "id_job=" . intval($row['id_job'])); |
|
| 440 | + sql_delete("spip_jobs_liens", "id_job=".intval($row['id_job'])); |
|
| 442 | 441 | // supprimer le job fini |
| 443 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 442 | + sql_delete('spip_jobs', 'id_job='.intval($row['id_job'])); |
|
| 444 | 443 | } |
| 445 | 444 | |
| 446 | 445 | /** |
@@ -511,17 +510,17 @@ discard block |
||
| 511 | 510 | // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
| 512 | 511 | // pour cause de timeout ou autre erreur fatale |
| 513 | 512 | $res = sql_allfetsel("*", "spip_jobs", |
| 514 | - "status=" . intval(_JQ_PENDING) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 513 | + "status=".intval(_JQ_PENDING)." AND date<".sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 515 | 514 | if (is_array($res)) { |
| 516 | 515 | foreach ($res as $row) { |
| 517 | 516 | queue_close_job($row, $time); |
| 518 | - spip_log ("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row,1), "job_mort"._LOG_ERREUR); |
|
| 517 | + spip_log("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row, 1), "job_mort"._LOG_ERREUR); |
|
| 519 | 518 | } |
| 520 | 519 | } |
| 521 | 520 | |
| 522 | 521 | // chercher la date du prochain job si pas connu |
| 523 | 522 | if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
| 524 | - $date = sql_getfetsel('date', 'spip_jobs', "status=" . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 523 | + $date = sql_getfetsel('date', 'spip_jobs', "status=".intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 525 | 524 | $next = strtotime($date); |
| 526 | 525 | } |
| 527 | 526 | if (!is_null($next_time)) { |
@@ -533,7 +532,7 @@ discard block |
||
| 533 | 532 | if ($next) { |
| 534 | 533 | if (is_null($nb_jobs_scheduled)) { |
| 535 | 534 | $nb_jobs_scheduled = sql_countsel('spip_jobs', |
| 536 | - "status=" . intval(_JQ_SCHEDULED) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 535 | + "status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 537 | 536 | } elseif ($next <= $time) { |
| 538 | 537 | $nb_jobs_scheduled++; |
| 539 | 538 | } |
@@ -601,7 +600,7 @@ discard block |
||
| 601 | 600 | } |
| 602 | 601 | |
| 603 | 602 | // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
| 604 | - if (file_exists($lock = _DIR_TMP . "cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 603 | + if (file_exists($lock = _DIR_TMP."cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 605 | 604 | return $texte; |
| 606 | 605 | } |
| 607 | 606 | |
@@ -672,20 +671,20 @@ discard block |
||
| 672 | 671 | $scheme = ''; |
| 673 | 672 | $port = 80; |
| 674 | 673 | } |
| 675 | - $fp = @fsockopen($scheme . $parts['host'], |
|
| 674 | + $fp = @fsockopen($scheme.$parts['host'], |
|
| 676 | 675 | isset($parts['port']) ? $parts['port'] : $port, |
| 677 | 676 | $errno, $errstr, 1); |
| 678 | 677 | |
| 679 | 678 | if ($fp) { |
| 680 | 679 | $host_sent = $parts['host']; |
| 681 | 680 | if (isset($parts['port']) and $parts['port'] !== $port) { |
| 682 | - $host_sent .= ':' . $parts['port']; |
|
| 681 | + $host_sent .= ':'.$parts['port']; |
|
| 683 | 682 | } |
| 684 | 683 | $timeout = 200; // ms |
| 685 | 684 | stream_set_timeout($fp, 0, $timeout * 1000); |
| 686 | - $query = $parts['path'] . ($parts['query'] ? "?" . $parts['query'] : ""); |
|
| 687 | - $out = "GET " . $query . " HTTP/1.1\r\n"; |
|
| 688 | - $out .= "Host: " . $host_sent . "\r\n"; |
|
| 685 | + $query = $parts['path'].($parts['query'] ? "?".$parts['query'] : ""); |
|
| 686 | + $out = "GET ".$query." HTTP/1.1\r\n"; |
|
| 687 | + $out .= "Host: ".$host_sent."\r\n"; |
|
| 689 | 688 | $out .= "Connection: Close\r\n\r\n"; |
| 690 | 689 | fwrite($fp, $out); |
| 691 | 690 | spip_timer('read'); |