Welcome Guest, Not a member yet? Register   Sign In
Hey guys
#11

[eluser]smilie[/eluser]
Yeah, that's one of the ways. I do wish to implement a better checks in the cron and if it crashes to report why it crashed and (if possible) to set status to 0...

Still working that one out Smile

Edit: fortunately it is an dedicated server, so I can do what ever I want (no restrictions what so ever!) Smile

Cheers,
Smilie
#12

[eluser]nilesh+[/eluser]
Yep I considered full access given the domain of the application. The ps hack may not work on systems where access to system or exec is not allowed.
#13

[eluser]smilie[/eluser]
I know, that's why I am really happy that I may do what ever I want (of course, taking in account security issues). But I already use exec() for some functionalities.

Cheers,
Smilie
#14

[eluser]paulipv[/eluser]
My daemon works like this:

Code:
$config = array(
'daemon'     => 'myDaemonName' ,
'pidLogFile' => '/var/log/daemon.log'
'maxThreads' => '50'
'resetAfter' => '60' // seconds
  )

/*  resetAfter = If max threads is reached then daemon will wait for every child to complete, however if resetAfter is configured, after time everything comes to normal.
  
  This prevent server load.

*/
  

$daemon = Daemon::singleton();
$daemon->set($config)->start();

// Multithread

while(true) {

  // Get database jobs
  for ($i;$i <= count($jobs);$i++) {
  
    $daemon->isChild() {
      // Do something;
    
    // External MVC
    $daemon->mvc('/controller/method' , $jobID , extraArgs);
  
   // External (path)
    $daemon->run('script_path' , $jobID , extraArgs);

   // External Url (json response)
   $response = $daemon->url(url , $jobID , extraArgs);
  
   $obj = json_decode($response);
   $obj->jobID  // jobID
   $obj->scriptRunDuration // how much take for script to complete
   $obj->extraArgs->arg1,2,3,4,5,etc

    // update table set status = 'completed' duration = $duration ...

   $daemon->killChild() // prevent zombies... (not necessary but for sure)
          
    } else {
       die('Fork failed, my system is b0rked!');
    }

  }

  $daemon->iterate(2); // relax daemon for 2 seconds =)

}
#15

[eluser]paulipv[/eluser]
Example with date.

We have a task that run every minute.

And looks like crontab: * * * * *

Code:
while (true) {

  $current   = $daemon->current();  
  $scheduled = $daemon->scheluded($jobDate);

  if (!$daemon->now() {
   // is not programmed to run now
  } else {
    
    // run task ...
    $nextScheludeDate = $daemon->next();

   update jobs set next_shedule_date = $nextScheludeDate
  
  }

  
  
  
}


Monitor from a linux server:
tail -f /var/log/daemon.log , there logs are rendered like:

[date] info: Starting daemon 'MyDaemonName' with PID: x
[date] info: Pid saved on /var/data/myDaemonName.pid

[date] info: Running job x with PID: pidID
[date] emerg: job x killed for high memory usage
[date] sys: Receive restart command




Theme © iAndrew 2016 - Forum software by © MyBB