Page 1 of 1
php auto execute
Posted: Fri Jan 13, 2006 10:41 am
by nincha
Is it possible to execute a php file automatically? If so, can any one provide a link or info?
Posted: Fri Jan 13, 2006 10:45 am
by John Cartwright
what do you mean automatically? Does that mean without a user physically going to a PHP page? Or you do want the page to be executed upon a certain time of hour/day/week/year
If it is the latter, then search for "cron job"
Posted: Fri Jan 13, 2006 10:49 am
by nincha
want the page to be executed upon a certain time of hour/day/week/year
Posted: Fri Jan 13, 2006 10:54 am
by John Cartwright
This is a useful tutorial that may help you :p
http://www.phpfreaks.com/tutorials/28/0.php
Posted: Fri Jan 13, 2006 12:18 pm
by Chris Corbyn
I'd just like to note that PHP supports the shebang line on UNIX based platforms too. This means that you don;t need to physically call the interpreter if you're running a script by cron or on the command line, providing you have execute permission on your file. it also means you don;t need the .php extension and so you can essentially write them as linux commands.
e.g. Create a file called php-command with no extension....
Code: Select all
#!/usr/bin/php
<?php
echo "Hello world!\n";
?>
Save it and chmod it to 0777
Place it in /usr/local/bin or somewhere in $PATH.
Code: Select all
-bash - $ php-command
Hello world!
-bash - $ _
Just a nice little extra to know
I beleive that should also work from the /cgi-bin directory of your web directory too, providing you add the HTTP content headers
Code: Select all
#!/usr/bin/php
<?php
echo "Content-type: text/html\n\n";
echo "Hello world!\n";
?>