php auto execute

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

php auto execute

Post by nincha »

Is it possible to execute a php file automatically? If so, can any one provide a link or info?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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"
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Post by nincha »

want the page to be executed upon a certain time of hour/day/week/year
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

This is a useful tutorial that may help you :p

http://www.phpfreaks.com/tutorials/28/0.php
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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";

?>
Post Reply