PHP3 Guide 2400/2401/2420
PHP3 Guide 1 WHY PHP? 1.1 WHAT IS PHP 3 4 2 PHP3 AND THE VIDEO SERVER 5 3 6 PHP3 SCRIPT 3.1 LIMITATIONS 3.2 REQUIREMENTS FOR GETTING STARTED: 3.3 SCRIPTS 3.3.1 COMPLETE SCRIPT EXAMPLES 3.3.2 SCRIPT GENERATED BY THE APPLICATION WIZARD 3.3.2.1 Get the script that the wizard in the Video Server has created 3.3.3 THE TASK-SCHEDULER 3.3.3.1 Syntax 3.3.3.2 Examples 3.3.4 PUT A NEW OR CHANGED SCRIPT INSIDE THE VIDEO SERVER: 3.3.5 HOW TO ACTIVATE THE SCRIPTS? 3.3.5.1 URL 3.3.5.2 Telnet 3.3.5.2.
PHP3 Guide 6 APPENDIX B - SHELL COMMANDS 32 6.1 32 7 7.1 COMMANDS APPENDIX C - PHP3 SCRIPT EXAMPLES SCRIPT EXAMPLES 35 36 Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application. Revision 0.
PHP3 Guide 1 Why PHP? PHP, which stands for "PHP: Hypertext Preprocessor" was chosen as the scripting language to use in some Axis Video products since: ! ! ! ! ! PHP is a well-known and widely used scripting language; in Feb 2001 an estimate of 23% of all Internet web servers used PHP (nearest "competing" script language was Perl with about 7%). The language syntax closely resembles Java, Perl and C, making it easy to learn for anyone with basic programming skills.
PHP3 Guide 1.1 What is PHP PHP (officially "PHP: Hypertext Preprocessor") is a server-side HTML-embedded scripting language. Simple answer, but what does that mean? An example: Example 1-1.
PHP3 Guide 2 PHP3 and the Video Server Axis has removed some functions from the standard PHP3, and created some additional functions to suit our products. The name of Axis´ modified version of PHP3 is called PHP3-Lite. The functions among others, that are removed are those that handle: ! ! ! Database functions PDF functions Mathematic functions Axis recommends checking that PHP3-Lite supports the functions required before creating custom scripts.
PHP3 Guide 3 PHP3 script Before making custom scripts Axis recommends looking at our PHP3-Lite manual (short description about this on the previous page). You can find the manual on the Axis Web site: http://www.axis.com Note: Axis Communications AB provides no guarantee that any of the examples shown here will work for a particular application.
PHP3 Guide 3.2 Requirements for getting started: ! ! ! Web browser FTP Client Text Editor Recommended: ! FTP Server ! SMTP Server Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application. Revision 0.
PHP3 Guide 3.3 Scripts Tip: A very useful program to fetch or upload a script to the product, is Ultra Edit; This can be downloaded from the following Web site: http://www.ultraedit.com/ Tip: To log all possible errors, include the row error_reporting(E_ALL); in the script. Turn off this option with the row: error_reporting(0); 3.3.1 Complete script examples It´s possible to create scripts and put them inside the video server.
PHP3 Guide 3.3.2 Script generated by the Application Wizard The wizard in the video server can generate the most basic scripts, and these can then be extended and modified to fit a particular applications needs though Axis recommends creating the scripts from scratch and putting them inside the video server. How to accomplish the above, follow the instructions on the next page. Axis Communications AB does not provide support for application development of any kind.
PHP3 Guide 3.3.2.1 Get the script that the wizard in the Video Server has created Start by going through the wizards in the Video Server, then open an FTP session to the Video Server. Follow the instructions below to see how this can be accomplished: Open a DOS session and type the following commands: 1. Go to the path where the script is saved Eg: c:\axis\php 2. ftp Eg: ftp 10.13.9.73 3. Type the user name Eg: user name: root 4. Type the password Eg: password: pass 5.
PHP3 Guide Note: After having created a script with the application wizard, push the remove button or restart the unit before creating a new one! (This doesn't work if it's a script that has been created from scratch, then the script has to be killed by using telnet). After following the steps on the previous page, it is possible to look at the script that the wizard in the Video Server has created (use for example Notepad to open the script).
PHP3 Guide to valid file. $user = "anonymous"; The user to login as. $pass = "pass"; The password to use for the user. $port = "21"; The port to connect to. $passive_mode = "no"; Choose passive mode on (“yes” or off (“no”). The time, in seconds, to stay in the script. Specifies whether to leave the FTP-function or not, after upload, ($time="0") leave the FTP function ($time="-1") continue uploading Specifies the (approximate) delay in milliseconds between image taken when $time="-1".
PHP3 Guide to utask in order for it to reread /etc/task.list. This can be done by issuing the system (Telnet) command 'kill -10 '. 3.3.3.1 Syntax An entry in /etc/task.list has the following syntax : %:; = is the event description = is the program to start = are the arguments to be passed to . The maximum number of events is 64. An event description should contain one or more of the following definitions.
PHP3 Guide :;:;. These patterns are read from /tmp/utasksocket. By default, if an event is trigged, the program runs, exits and starts again as long as the triggering event is valid. utask start at most five (5) child-processes. When the maximum number of child processes has been exceeded, utask has to decide how to proceed. utask usually kills the process with the lowest priority (if the pending task has a higher priority than this process).
PHP3 Guide Upload a PHP3 file into the Video Server 1. Open a DOS session and open an FTP session from the path where the PHP3 file resides. Eg: c:\axis\PHP 2. Check that the file exists by typing dir Eg: c:\axis\PHP dir 3. If the file is to be executed as a link, then the file has to have the extension PHP3. If the file doesn't have this then rename the file with the DOS command ren. Eg: c:\axis\PHP ren script.doc (the old filename) script.php3 (the new filename) 4.
PHP3 Guide 3.3.5 How to activate the scripts? Important! Before activating a new script, restart the video server. 3.3.5.1 URL This is the way Axis recommends to activate the scripts. To activate the new script, follow the instructions below: 1. Open the browser (Tested browsers are Netscape and Internet Explorer) 2. Type the IP-address for the Video Server in the URL: Eg: 10.13.9.75/local 3. If the file doesn’t appear click the Refresh button in the browser. To activate the script select the file.
PHP3 Guide 3.3.5.2 Telnet For development it might be useful to connect to the Network Camera by Telnet. Depending on what product is used, this is either enabled by default and have authentication or can be enabled by editing the /etc/inittab. If the product require editing of the /etc/inittab, there will be no authentication for the Telnet connection and no password will be required for access. Important: Enable this option for experimental use only.
PHP3 Guide Go back to the ftp session and continue: ftp> put inittab 200 Command okay. 150 Opening data connection. 226 Transfer complete. ftp: 1414 bytes sent in 0,00Seconds 1414000,00Kbytes/sec. 250 Command successful. ftp> by 221 Goodbye. Restart the camera and it will be possible to access with Telnet. Activate the script through telnet To activate the script through telnet, follow the instructions below: 1. Open a telnet connection to the Video Server. 2.
PHP3 Guide Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application. Revision 0.
PHP3 Guide 4 Troubleshooting Tip: To log all possible errors include the following row in the script: error_reporting(E_ALL); Turn off this option with the following row: error_reporting(0); 4.1 PHP3 script related problems Axis Communications AB does not provide support for application development of any kind. The information here is provided "as is", and there is no guarantee that any of the examples shown will work in your particular application. 4.
Appendix A – Included Application 5 Appendix A – Included application Note: The general rule is to not use a function when it’s usage is not fully understood! 5.1 Introduction This document explains some of the applications that are shipped with the Axis 2400/2401 products. These applications are: ! ! ! sh, the shell used on the cameras (a modified sash) bufferd, a program for buffering images utask, a program for scheduling tasks (similar to cron or at).
Appendix A – Included Application 5.2.1 Built in commands The shell includes a help command, which lists the available functions built in the shell (see also Appendix B). 5.3 The image-buffer - bufferd The application bufferd captures images and stores them on the ram-disk in a FIFO-order, that is, the newest captured image overwrites the oldest. By default initd starts a bufferd as a daemon. This daemon is listening for messages on the socket /tmp/bufferdsocket.
Appendix A – Included Application (www.axis.com) under Camera & Video developer pages. -postdelay Delay between images in milliseconds. -predelay Same as -postdelay but sets an additional variable. -pre Number of pre-alarm pictures, i.e. number of images to save before stopping the buffer. -post Number of post-alarm pictures, i.e. the number of images to save after stopping the buffer. -format
Appendix A – Included Application 5.3.2 Examples This example shows how to take one(1) image with camera one(1). The resulting image will be of size 640x480 and with other attributes set according to what the camera is set to. The image will be stored in /tmp/SNAP/ and named snapshot. bufferd -start -buffername SNAP -snapshot -pre 1 -format snapshot -uri ftp://axiscgi/jpg/1/fullsize.jpg The following example can be used in a PHP3-script, and is equivalent to the example above.
Appendix A – Included Application bufferd -start -buffername ALARM -uri ftp://axis-cgi/jpg/1/halfsize.jpg -pre 5 -post 2 -postdelay 2000 (This starts the buffer and can be specified in a start-up script or as an event for utask) When an event occurs, as specified for utask (see below) the following command sequence is used to handle the buffer: bufferd -stop ALARM { handle images} bufferd -reset ALARM bufferd -start -buffername ALARM -uri ftp://axis-cgi/jpg/1/halfsize.
Appendix A – Included Application function alert($host,$protocol,$port,$message) { ... } $host (not null) The host-name or address to send the alert to. $protocol Specify the protocol (0 = TCP, 1 = UDP). Default is '0' $port The port to connect to. Default is '15' $message the message to be sent (ASCII) The timeout for a connection-attempt is 60 seconds. On error the function returns '1' (connection failed), '2' (a parameter was missing) or '$SOCK_CONNECT_FAILED'.
Appendix A – Included Application "sequence_max". $countermax Defines the suffix maximum index. Only applies when $suffix = "sequence". $startcount Defines start value for the suffix index. Only applies when $suffix = ("sequence"|"sequence_max"). $port Port on the FTP-server to connect to. Choose passive mode. "on" or "off". $passive_mode In passive mode, data connections are initiated by the client, rather than by the server.
Appendix A – Included Application $subject Message subject (default is 'no subject') $from (not null) Message's author $reply Reply should be sent to this user (default is $from) $to (not null) Recipients $copy Copy the message to other recipients $file Message read from file $attach File to attach The script requires that a valid mail-server has been entered in the settings for the camera.
Appendix A – Included Application Returns '1' if it reads "ON", otherwise returns '0'. $num_of_checks is the number of attempts to read the file '/tmp/pppstat.log'. function ppp_start() { ... } Called from ppp_online(). Sends SIGUSR1 (10) to the currently running ppp-wrapper. If the wrapper isn't running the function returns '-1' and an error is logged in the syslog. function ppp_stop() { ... } Called from ppp_offline(). Sends SIGUSR2 (12) to the currently running ppp-wrapper.
Appendix A – Included Application function ppp_offline($behavior, $sec) { ... } Close ppp connection $behavior describes the type of behavior of the ppp connection and can be either "CloseAfter" or "Optimized". $sec is the time in seconds to wait before calling ppp_stop() if $behaviour="CloseAfter". If $behaviour="Optimized" no waiting is done, ppp_stop is called immediatly. 5.4.
Appendix A – Included Application log("upload script - Could not put the file"); } else if($res == 4) { log("upload script - something wrong with parameters"); } else if($res == 5) { log("upload script - could not turn passive mode on/off"); } ?> The second example depicts how to use the mail-function, and is the script mentioned as mail_syslog.php in the utask-example:
Appendix B - Shell Commands 6 Appendix B - Shell Commands 6.1 Commands Command Options ([]=optional, <>=required) Description cat [filename ...] cd [dirname] Change the current directory to [dirname]. Default value of is the environment variable '$HOME' chgrp [filename ...] Change group identity of to chmod [filename ...] Change mode of to chown [filename ...
Appendix B - Shell Commands for in do Conditional execution. is the name of the variable which will be substituted by each entry in . is string of arguments separated by spaces. is the command that shall be run for each entry in the list. if ( ) Conditional statement. can be any of ==, !=, >=, <=, < or > . No nested expressions or real arithmetic, but if-statements can be nested themselves.
Appendix B - Shell Commands rm [filename ...] Remove files rmdir [dirname ...] Remove empty directories setenv Change or add an environment variable sethostname Set the environment variable $HOSTNAME to setdomainname [domainname] Set the environment variable $DOMAINNAME to sleep [sec] Suspend the shell for seconds source Read and execute in current shell environment .
Appendix C - PHP3 Script Examples 7 Appendix C - PHP3 Script Examples On the following pages complete PHP3 scripts can be found, which are customized for the most common applications. To run these scripts a task.list file for each script is attached. This is needed because utask reads the file /etc/task.list at startup, and parses it for event entries. Therefore, it must be fetched to be able to run the script in an automatic fashion. (See also section 3.3.3 The task-Scheduler.) The script and task.
Appendix C - PHP3 Script Examples 7.1 Script examples Important: Before using the scripts on the following pages please read chapter 1 and 2 in this document. This script will upload these specified images buffers via FTP and the Ethernet interface (alarm_ftp_net.php3) Edit your own parameters below this line. $buffer_prefix = "CAM"; $sources = "1"; $image_format = "fullsize"; $pre = 2; $post = 2; $predelay = 1000; $postdelay = 1000; $ftp_server = "10.13.9.
Appendix C - PHP3 Script Examples There is no need to edit anything below this line for($c=0;$c<(strlen($sources));$c++) { // Stop the, by utask, //started buffers $command="bufferd -stop -buffername ".$buffer_prefix.substr($sources,$c,1); system($command); } error_reporting(0); for($c=0;$c<(strlen($sources));$c++) { // For each buffer specified $status_file = "/tmp/".$buffer_prefix.substr($sources,$c,1)."/status"; while(!is_file($status_file)) { // Wait until bufferd is //ready with the images, i.e.
Appendix C - PHP3 Script Examples While($file_name = readdir($buffer_handle)) { // And for each file in the //corresponding buffer /directory if(($file_name != ".") &&($file_name != "..")) { // That is a regular file $file = "/tmp/".$buffer_prefix.substr($sources,$i, 1)."/".$file_name; $destination_name = $destination . $buffer_prefix.substr($sources,$i,1); $destination_name .
Appendix C - PHP3 Script Examples TASK.LIST (Needed to run the script above and it’s important that the file is named task.list) once immune % /bin/bufferd : -start -buffername CAM1 -pre 2 -post 2 predelay 1000 -postdelay 1000 -uri ftp://jpg/1/fullsize.jpg; date(w(0,1,2,3,4,5,6)) pattern((IO0:/)) immune once % /bin/sh : -c php /etc/httpd/html/alarm_ftp_net.php3; Axis Communications AB does not provide support for application development of any kind.
Appendix C - PHP3 Script Examples This script will upload specified image buffers via FTP and the Ethernet interface, and also send a mail as specified. (alarm_ftp_note_smtp_net.php3) Edit your own parameters below this line.
Appendix C - PHP3 Script Examples There is no need to edit anything below this line. for($c=0;$c<(strlen($sources));$c++) { $command="bufferd -stop -buffername ".$buffer_prefix.substr($sources,$c,1); system($command); } $command = "smtpclient"; $command .=" -L -S ".$smtp_server; $command .=" -s ".$subject; $command .=" -f ".$from; $command .=" -r ".$reply; $command .=" -c ".$cc; $command .=" -b ".$body; $command .=" ".
Appendix C - PHP3 Script Examples else { // Passive mode successfully set for($i=0;$i < (strlen($sources));$i++) { // For each buffer specified $directory="/tmp/".$buffer_prefix.substr($sources,$i,1); $buffer_handle = opendir($directory); while($file_name = readdir($buffer_handle)) { // And for each file in the //corresponding buffer directory if(($file_name != ".") &&($file_name != "..")) { // That is a regular file $file = "/tmp/".$buffer_prefix.substr($sources,$i,1)."/".
Appendix C - PHP3 Script Examples $command="bufferd -start -buffername ".$buffer_prefix.substr($sources,$c,1)." -pre ".strval($pre)." post ".strval($post)." -predelay ".strval($predelay)." -postdelay ".strval($postdelay)." -uri ftp://jpg/".substr($sources,$c,1)."/".$imageformat.".jpg"; system($command); } ?> TASK.LIST (Needed to run the script above and it’s important that the file is named task.
Appendix C - PHP3 Script Examples This script will upload these specified sequential images via FTP and the Ethernet interface. The uploaded images will be named according to the parameter $suffix. (seq_ftp_net.php3) Edit your own parameters below this line. $buffer_prefix = "SNAP"; $sources = "1"; $image_format = "fullsize"; $delay = 2000; $file_format = "snapshot"; $ftp_server = "10.13.9.
Appendix C - PHP3 Script Examples //$suffix = "sequence_max"; // Or "sequence_max" for an //index up to the internal //maximum integer There is no need to edit anything below this line.
Appendix C - PHP3 Script Examples if(($suffix=="sequence") && $current_counter > $counter_max) { // If the loaded index exceeds //the specified maximum, reset //index $current_counter = 1; if($fd = fopen("/tmp/counter","w")) { $buf = fwrite($fd,strval($current_counter)); fclose($fd); } } error_reporting(E_ALL); $session = ftp_connect($ftp_server, $port); if($session) { // Connection successfully //established if(ftp_login($session, $user, $pass)) { // Successful login attempt if (!ftp_pasv($session, $passi
Appendix C - PHP3 Script Examples if($suffix == "date") { $tinfo = getdate(time()); $dest .= "_" . conv($tinfo["year"]); $dest .= "-" . conv($tinfo["mon"]); $dest .= "-" . conv($tinfo["mday"]); $dest .= "_"; $dest .= conv($tinfo["hours"]); $dest .= conv($tinfo["minutes"]); $dest .= conv($tinfo["seconds"]); } else if($suffix == "sequence_max") { $dest .= "_" .
Appendix C - PHP3 Script Examples $dest .= ".jpg"; error_reporting(0); if(is_file($source_file)) { // If the source file is a //present if(!ftp_put($session, $dest, $source_file, FTP_BINARY)) { // Upload the source file $failures++; error_log("Could not upload file ".$source_file." as ".$dest." on ".
Appendix C - PHP3 Script Examples else $session_time -= ($current_time["usec"] $start_time["usec"])/1000000; } if($session_time>=$time) error_log("Timed upload complete",0); if($failures>=(strlen($sources)*2)) error_log("Too many consecutive failures",0); } } else { ftp_quit($session); error_log("Could not log in as ".$user." on ".$ftp_server,0); } ftp_quit($session); } else { error_log("Could not connect to ".$ftp_server.":".
Appendix C - PHP3 Script Examples This script will upload these specified sequential images via FTP and the Ethernet interface. The uploaded images will be ordered in a structure defined by their date. (seq_ftp_net_structured.php3) Edit your own parameters below this line. $buffer_prefix = "SNAP"; $sources = "1"; $image_format = "fullsize"; $delay = 2000; $file_format = "snapshot"; $ftp_server = "10.13.9.
Appendix C - PHP3 Script Examples There is no need to edit anything below this line. error_reporting(0); function conv($value) { // A function for converting //single digit integers into //two digit integers if($value < 10) { $value = "0$value"; } return strval($value); } for($c=0;$c<(strlen($sources));$c++) { // Start the buffers as //specified by the parameters //above $command="bufferd -start -buffername "; $command.=$buffer_prefix.substr($sources,$c,1); $command.
Appendix C - PHP3 Script Examples for($c=0;$c
Appendix C - PHP3 Script Examples if(!ftp_put($session, $dest, $source_file, FTP_BINARY)) { // Upload the source file $failures++; error_log("Could not upload file ".$source_file." as ".$dest." on ".$ftp_server,0); } else { // If successful upload, //remove the uploaded file //indicating capture of a new //image $failures=0; unlink($source_file); } } else { error_reporting(E_ALL); $failures++; error_log("No such file: ".
Appendix C - PHP3 Script Examples else $session_time -= ($current_time["usec"] $start_time["usec"])/1000000; } if($session_time>=$time) error_log("Timed upload complete",0); if($failures>=(strlen($sources)*2)) error_log("Too many consecutive failures",0); } } else { error_log("Could not log in as ".$user." on ".$ftp_server,0); } ftp_quit($session); } else { error_log("Could not connect to ".$ftp_server.":".
Appendix C - PHP3 Script Examples This script will upload image buffers specified by use of SMTP and the Ethernet interface (alarm_smtp_net.php3) Edit your own parameters below the line. $buffer_prefix = "CAM"; $sources = "1"; $image_format = "fullsize"; $pre = 2; $post = 2; $predelay = 1000; $postdelay = 1000; $smtp_server = "mail.somewhere.com"; $subject = "test"; $from = " someone@somewhere.com"; $reply = " someone@somewhere.com "; $cc = " someone@somewhere.
Appendix C - PHP3 Script Examples There is no need to edit anything below the line. error_reporting(E_ALL); error_log("Stopping buffer(s)",0); for($c=0;$c<(strlen($sources));$c++) { // Stop the, by utask, //started buffers $command="bufferd -stop -buffername ".$buffer_prefix.substr($sources,$c,1); system($command); } for($c=0;$c<(strlen($sources));$c++) { // For each buffer //specified $status_file = "/tmp/".$buffer_prefix.substr($sources,$c,1).
Appendix C - PHP3 Script Examples error_log("Restarting buffer(s)",0); for($c=0;$c<(strlen($sources));$c++) { // Reset and restart //buffers $command="bufferd -reset -buffername ".$buffer_prefix.substr($sources,$c,1); system($command); $command="bufferd -start -buffername ".$buffer_prefix.substr($sources,$c,1)." -pre ".strval($pre)." post ".strval($post)." -predelay ".strval($predelay)." postdelay ".strval($postdelay)." -uri ftp://jpg/".substr($sources,$c,1)."/".$image_format.".
Appendix C - PHP3 Script Examples This script will upload sequential images specified by use of FTP and the Ethernet interface. The uploaded images will be ordered in a structure defined by their date. Upon alarm event (indicated by an existing file named according to $alarm_file) images from the alarm buffers will be uploaded and a mail will be sent as specified by the appropriate parameters (seq_ftp_alarm_ftp_note_smtp_net.php3) Edit your own parameters below the line.
Appendix C - PHP3 Script Examples $time = 60; $alarm_file = "/tmp/alarm"; // The time, in seconds, to //stay in this script. A //value of -1 means //indefinetly.
Appendix C - PHP3 Script Examples There is no need to edit anything below the line. error_reporting(0); unlink($alarm_file); error_reporting(E_ALL); for($c=0;$c<(strlen($alarm_sources));$c++) { // Stop the alarm buffers $command="bufferd -stop -buffername ".$alarm_buffer_prefix.substr($alarm_sources,$c,1); system($command); } // Send the mail $command = "smtpclient"; $command .=" -S ".$smtp_server; $command .=" -s ".$subject; $command .=" -f ".$from; $command .=" -r ".$reply; $command .=" -c ".
Appendix C - PHP3 Script Examples while($file_name = readdir($buffer_handle)) { if(($file_name != ".") &&($file_name != "..")) { // And for each regular //file in that directory $file = "/tmp/".$alarm_buffer_prefix.substr($alarm_sou rces,$i,1)."/".$file_name; $destination_name = $alarm_destination.$alarm_buffer_prefix.substr ($alarm_sources,$i,1); $destination_name .= strchr($file_name,"_"); if(!ftp_put($session, $destination_name, $file, FTP_BINARY)) { // Upload file error_log("Could not upload file ".
Appendix C - PHP3 Script Examples //integers into two digit //integers if($value < 10) { $value = "0$value"; } return strval($value); } for($c=0;$c<(strlen($seq_sources));$c++) { // For each source //specified, start a buffer $command="bufferd -start -buffername "; $command.=$seq_buffer_prefix.substr($seq_sources,$c,1); $command.=" -snapshot -pre 1 -predelay "; $command.=strval($delay); $command.=" -uri ftp://jpg/"; $command.=substr($seq_sources,$c,1); $command.="/"; $command.=$seq_image_format; $command.
Appendix C - PHP3 Script Examples while( ($failures<(strlen($seq_sources)*2)) && ( ($session_time<$time)||($time==-1) )) { // Upload images as long as //not too many errors have //occured and session time //hasn't been exceeded // Check if an alarm has trigged error_reporting(0); if(is_file($alarm_file)) { handle_alarm($session,$alarm_file); } error_reporting(E_ALL); $loop_start = gettimeofday(); $active_buffer++; if($active_buffer==strlen($seq_sources)) { // Loop through the indexes //specified as sources
Appendix C - PHP3 Script Examples if(!ftp_put($session, $dest, $source_file, FTP_BINARY)) { // Upload the source file $failures++; error_log("Could not upload file ".$source_file." as ".$dest." on ".$ftp_server,0); } else { // If successful upload, //remove the uploaded file //indicating capture of a //new image $failures=0; unlink($source_file); } error_reporting(E_ALL); } else { error_reporting(E_ALL); $failures++; error_log("No such file: ".
Appendix C - PHP3 Script Examples // Calculate session time $session_time = ($current_time["sec"] $start_time["sec"]); if($current_time["usec"] > $start_time["usec"]) $session_time += ($current_time["usec"] - $start_time["usec"])/1000000; else $session_time -= ($current_time["usec"] - $start_time["usec"])/1000000; error_reporting(0); if(is_file($alarm_file)) { handle_alarm($session,$alarm_file); } error_reporting(E_ALL); } if($session_time>=$time) error_log("Timed upload complete",0); if($failures>=(strlen
Appendix C - PHP3 Script Examples TASK.LIST (Needed to run the script above and it’s important that the file is named task.list) once immune % /bin/bufferd : -start -buffername CAM1 -pre 2 -post 2 predelay 1000 -postdelay 1000 -uri ftp://jpg/1/fullsize.jpg; date(w(0,1,2,3,4,5,6)) pattern((IO0:/)) immune once % /bin/sh : -c php /etc/httpd/html/seq_ftp_alarm_ftp_note_smtp_net.