PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Grigori Kochanov   Daemon Emulation   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: run this from the comand line
Class: Daemon Emulation
Create and manage daemon processes
Author: By
Last change: addid auto-termination sample
Date: 18 years ago
Size: 457 bytes
 

Contents

Class file image Download
_____________________________________
to stop the process run
kill `cat daemon.pid`
_______________________________________
<?php
include 'daemon.class.php';

//N.B.: don't open the database connection before daemonizing
new Daemon();

for (
$i=0;$i<3;++$i){
    echo
'script is using '.memory_get_usage()." bytes\n";
   
$a[] = str_repeat('a',100000);
   
sleep(1);
}

//terminate the daemon with 20% probability
(!mt_rand(0,5)) and Daemon::terminate();

?>