database lock for frequent processes
[Pman.Core] / Heartbeat.php
1 <?php
2
3 // check if database is workign - used by nagios checking - to see if server is really up.
4
5 require_once 'Pman.php';
6
7 class Pman_Core_Heartbeat extends Pman
8 {
9     function getAuth()
10     {
11         return true;
12     }
13     
14     function get($req, $opts = array())
15     {
16         $this->post($req);
17         die("POST only");
18     }
19     
20     function post($req)
21     {
22         $this->initErrorHandling();
23         
24         if ($this->database_is_locked()) {
25             die("FAILED");
26         }
27         
28         
29         $cd = DB_DataObject::Factory('core_enum');
30         $cd->setFrom(array(
31             'etype' => 'heartbeat',
32             'name' => 'last_update'
33         ));
34         if (!$cd->count()) {
35             $cd->display_name = date("Y-m-d H:i:s");
36             $cd->insert();
37             die("OK - HEARTBEAT WORKING");
38         }
39         $cd->find(true);
40         $cc = clone($cd);
41         $cd->display_name = date("Y-m-d H:i:s");
42         $cd->update($cc);
43         die("OK - HEARTBEAT WORKING");
44     }
45     
46      
47     function onPearError($err)
48     {
49       //  print_r($err);
50         die("FAILED");
51     }
52     function onException($err)
53     {
54       //  print_r($err);
55         die("FAILED");
56     }
57     
58    
59 }