Q : What is required to install PHPMotionDetect
A : A supported webcam + streamer(Xawtv) + PHP
Philips WebCams http://www.smcc.demon.nl/webcam/
A commandline tool that can take a snapshot and save it to a file.
Streamer is a part of xawtv.
PHP is an HTML-embedded scripting language.
You need to compile supprt for GD to see any of the
statistics plots on the web interface
You need to set 'register_globals=On' in php.ini.
Apache (optional - only for the www interface)
Mysql Server (optional - only for the www interface)
Q : How do I install the thing ?
1. Unpack the downloaded files somewhere
> gunzip phpmotiondetect.tgz
> tar xfz phpmotiondetect.tar
> cd phpmotiondetect
For access to the WWW interface unpack the files somewhere,
where the Apache server can see the files
and you are done with the www-setup
2. Create the MySQL database for archiving (optional)
If you want to create a new database do
mysql -u usename -h hostname -p
mysql> CREATE DATABASE motiondetect;
To create the tables 'log' and 'images' in the database 'motiondetect'
issue the following command.
mysql -u usename -h hostname -p motiondetect' < motiondetect.sql
NB : Any database name can be used !
3. edit conf.php
conf.php contains settings that determine the behavior of phpmotiondetect
Please be careful that the user that runs the script should have read/write access
4. Test that the script works
set '$usecron=1' and '$verbose=20' in conf.php.
This causes the script to run only once and then exit, and write plenty of
debug information to the screen when running.
Now run the motiondetect script as :
> php -q motiondetect.php
motiondetect(20) 1 : USING DB (firstname.lastname@example.org)
motiondetect(20) 1 : SELECTED DB -- OK (email@example.com)
motiondetect(20) 5 : Using existing old=/tmp/kontor_old.jpeg
motiondetect(20) 5 : Snapshot command (New snapshot) :
/usr/bin/streamer -s 320x240 -o /tmp/kontor_new.jpeg >& /dev/null
motiondetect(20) 10 : Reading /tmp/kontor_new.jpeg.
motiondetect(20) 10 : Reading /tmp/kontor_old.jpeg.
motiondetect(20) 1 : snap=0001, New=101.5, Ref=102.4, Diff= -0.8
motiondetect(20) 5 : Insert 'log' entry into DB
Warning: Unable to create '/tmp/kontor_old.jpeg':
Permission denied in /var/www/html/develop/phpmotiondetect/motiondetect.php
on line 90
motiondetect(20) 1 : Failed to copy
/tmp/kontor_new.jpeg to /tmp/kontor_old.jpeg
In the example above permissions were not set properly for $outdir
This was fiex and the output now shows :
When you can run the script without any errors you are ready to start
5. Detect motion
You can run the motiondetect.php script in two modes :
5a : Stand alone
In this mode set '$usecron=0' in conf.php,
Set '$verbose=1' to get some data written to the console, just to check that
everything is working. Set '$verbose=-1' when everything is working OK.
and from the command line start the motion detection by
> php -q motiondetect.php
5b : Crontab mode
You can run the motiondetect.php script from the crontab.
You can set crontab up to running the script down to once per minute.
Make sure the script is working properly. Then set
Now update crontab for the user you want to run the script with something
like : (replace with proper paths)
* * * * * /usr/bin/php -q /var/www/html/phpmotiondetect/motiondetect.php
6 : WWW interface
If you untarred the tgz file where they are available using an Apache server,
then simply go to that directory on the web server, using your favorite web
browser, and you should be able to browse the archived snapshot.
Running the detection script : motiondetect.php
Q: I see multiple version of PHP running and the same
snapshots appears many times in the DB-log. What gives ?
A : You are probably running the script using cron, but have $usecron=0 in the
conf.php file. This is really bad. Always set $usecron=1, when running
the script from cron.
Q: When running the script as stand alone program it simply dies
after a certain amount of time ?
A : This is probalbly caused by PHP dying due due to a 'maximum execution time'.
A script in php can only run for as many seconds as indicated by
max_execution_time = 60, as specified in the config file for php : php.ini.
Set this to a large number to esnure that PHP does not stop executing the script.
|© 2002, firstname.lastname@example.org