PHP 92
Command.php Guest on 5th June 2020 10:48:10 AM
  1. <?
  2. // --------------------------------------------------------------------------
  3. // Foto-Webcam.eu
  4. // Await command for webcam remote host
  5. //
  6. // Flori Radlherr, http://www.radlherr.de
  7. // This is free software, see COPYING for details.
  8. // --------------------------------------------------------------------------
  9. // ěščřžýáíéúů
  10. //header('Content-type: text/html; charset=utf-8');
  11. require "imgutil.php"; checkUploadVars() or die;
  12.  
  13.  
  14. $commandName= $webcam['workPath']."/tmp/command.txt";
  15. doLog("waiting for command...", "idle");
  16.  
  17. // Wait about 120s for a command
  18. for ($i=0; $i<240; $i++) {
  19.   // Check command file created by other process
  20.   if (@filemtime($commandName)>0) {
  21.     $cfile= fopen($commandName, "r");
  22.     if ($cfile) {
  23.       $cmd= fread($cfile,10000);
  24.       echo("command\n$cmd\n");
  25.       fclose($cfile);
  26.       unlink($commandName);
  27.       $cmd= preg_replace("/\n/", " ", $cmd);
  28.       doLog($cmd, "command-exec");
  29.       exit;
  30.     }
  31.   }
  32.   // Check if capture interval has expired, try capture
  33.   if (isset($webcam['captureInterval']) && $webcam['captureInterval']>0) {
  34.     $lastCapture= $webcam['workPath']."/tmp/lastCapture.txt";
  35.     $now= time();
  36.     // honour configured offset, shown time includes offset
  37.     if (isset($webcam['captureOffset'])) {
  38.       $now-= $webcam['captureOffset'];
  39.     }
  40.     $towait= ($now % $webcam['captureInterval']);
  41.     // Conditions for capturing:
  42.     // - time frame within 20sec after interval has come
  43.     // - last capture trigger is longer than 60sec old
  44.     if ($towait<55 && ($now[email protected]filemtime($lastCapture))>120) {
  45.       // remember this event by file timestamp
  46.       touch($lastCapture, $now);
  47.       // generate image stamp
  48.       $stamp= strftime("%Y%m%d_%H%M", $now);
  49.       // generate command for camera host
  50.       $webcam['lastCommand']= $now;
  51.       echo("command\n$now\nwebcam_capture $stamp\n");
  52.       doLog("state=capture-command stamp=$stamp", "info");
  53.       exit;
  54.     }
  55.   }
  56.   usleep(500000); // wait 500ms
  57. }
  58.  
  59. ?>

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.