php auto execute
Moderator: General Moderators
php auto execute
Is it possible to execute a php file automatically? If so, can any one provide a link or info?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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....
Save it and chmod it to 0777
Place it in /usr/local/bin or somewhere in $PATH.
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
e.g. Create a file called php-command with no extension....
Code: Select all
#!/usr/bin/php
<?php
echo "Hello world!\n";
?>Place it in /usr/local/bin or somewhere in $PATH.
Code: Select all
-bash - $ php-command
Hello world!
-bash - $ _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";
?>