Ich bin mit Daemons herumalbern, und fragte mich, wie machbar (in Bezug auf Speicher-und CPU-Nutzung und Zuverlässigkeit) ist es dies zu tun PHP:Wie machbar ist ein Daemon in PHP geschrieben, mit ignore_user abort und set_time_limit (0)
<?php
// Ignore user aborts and allow the script
// to run forever
ignore_user_abort(true);
set_time_limit(0);
$fp = fopen('loop.log', 'w');
fwrite($fp, date('Y-m-d H:i:s') . ' Started' . PHP_EOL);
while(1) {
fwrite($fp, date('Y-m-d H:i:s') . ' Looped' . PHP_EOL);
if (file_exists('loop.stop')) {
break;
}
// Sleep for 100 seconds
sleep(100);
}
fwrite($fp, date('Y-m-d H:i:s') . ' Stopped' . PHP_EOL);
fclose($fp);
Dieses einfache Beispiel (aus dem PHP-Handbuch angepasst für ignore_user_abort) ist nur der Container-Skript. Die eigentliche Funktionalität wird innerhalb der while
Schleife platziert.
Ich habe dieses Skript seit 7 Stunden auf meinem Laptop laufen, und es sieht gut aus, aber es tut nicht viel. Hat jemand anderes das versucht?