473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calling php script with cron - need shebang?

In regard to running php scripts with cron -

Here is a sample script:

<?php
//debug.php
echo "<br> This is a test";
?>

I can call debug.php from a web page on my site like this:

include 'debug.php';

But what if I want to call that same script using cron?

Do I need to modify the script like this:

#!/usr/bin/php -q
<?php
//debug.php
echo "<br> This is a test";
?>

Do I need to include the shebang (#!/usr/bin/php -q) for a php script to be
called from cron?
Jul 17 '05 #1
5 9174

"deko" <no****@hotmail.com> wrote in message
news:0I******************@newssvr25.news.prodigy.c om...
In regard to running php scripts with cron -

Here is a sample script:

<?php
//debug.php
echo "<br> This is a test";
?>

I can call debug.php from a web page on my site like this:

include 'debug.php';

But what if I want to call that same script using cron?

Do I need to modify the script like this:

#!/usr/bin/php -q
<?php
//debug.php
echo "<br> This is a test";
?>

Do I need to include the shebang (#!/usr/bin/php -q) for a php script to be called from cron?


If you are calling the php script from the command line without shebang you
will need to execute it by typing
$ php script.php

With a shebang it can be called as follows
$ script.php

makesure you chmod it +x though, otherwise it won't run at all.

For a tutorial on PHP on the Command line
http://www.sitepoint.com/article/php-command-line-1
Jul 17 '05 #2
> If you are calling the php script from the command line without shebang
you
will need to execute it by typing
$ php script.php

With a shebang it can be called as follows
$ script.php


So it is only when I call the script from the command line that I need the
shebang? Then no modification is needed to run my script using cron...
that's what I thought, but wasn't sure.... thanks...
Jul 17 '05 #3
On Wed, 14 Jul 2004 15:15:04 GMT, "deko" <no****@hotmail.com> wrote:
If you are calling the php script from the command line without shebang

you
will need to execute it by typing
$ php script.php

With a shebang it can be called as follows
$ script.php


So it is only when I call the script from the command line that I need the
shebang? Then no modification is needed to run my script using cron...
that's what I thought, but wasn't sure.... thanks...


no.

running a script from a cron job is the same as running it from the
command line (more or less, see note [1] below).

from the command line, you can invoke a php script in two ways:

$ php [-q] /path/to/script.php

or

$ /path/to/script.php

in the second method, the script _must_ have a shebang specifying the
location of your php binary, eg. #!/usr/local/bin/php

entries in your crontab are the same, eg:

45 3 * * * /usr/local/bin/php -q /path/to/script.php

or

45 3 * * * /path/to/script.php

in the second method the script must also have a shebang.
[1] note that your cron job will almost certainly not know about any
PATH information you may have set up in your shell, so you must always
give the full path to the php binary if you are invoking your script
using the first method in the case above.

Jul 17 '05 #4
Note that Apache ENV variables doesn't exists when you run it in shell.

Savut
http://www.savut.com

"deko" <no****@hotmail.com> wrote in message
news:Y5******************@newssvr25.news.prodigy.c om...
If you are calling the php script from the command line without shebang

you
will need to execute it by typing
$ php script.php

With a shebang it can be called as follows
$ script.php


So it is only when I call the script from the command line that I need the
shebang? Then no modification is needed to run my script using cron...
that's what I thought, but wasn't sure.... thanks...


Jul 17 '05 #5
"deko" <no****@hotmail.com> wrote in message news:<0I******************@newssvr25.news.prodigy. com>...
<snip>
Do I need to include the shebang (#!/usr/bin/php -q) for a php script to be
called from cron?


FWIW, for most of the servers, this method won't work as they use
mod_php. So, in that case you need to use wget.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Michael Appelmans | last post by:
I'm a php novice and am developing a shopping cart application for a client who is hosted on a unix server. The hosting service requires that each php file have #!/usr/local/bin/php at the top....
29
by: deko | last post by:
Is there a way to get my script to run on regularly scheduled intervals without using cron? My hosting provider sucks... cannot use cron... I was thinking perhaps I could create a file every hour...
7
by: paranoid-android | last post by:
I have a personal webserver installed and wish to run a script daily on my database. How would I achieve this?? Does anyone have any sample code?? regards
2
by: volantecho | last post by:
hi, i m using webmin to create a cron job of a php script. While i click on 'run it now', it works, generate the output. However, the php script doesnt execute for every minutes which i've set...
6
by: metaperl | last post by:
Hello, I am responsible for converting 30 loosey-goosey Perl scripts into 30 well-documented easy to understand and use Python scripts. No one has said anything in particular about how this...
3
by: dburdick | last post by:
I was referred to this forum as this may be a php specific problem. Some kind of configuration problem maybe. I have some php files that connect to a mysql database and are run as cron jobs. ...
4
by: J. Frank Parnell | last post by:
Hi there, I have a list of links which point to e.g. thescript.php?album=somePictures1 thescript.php?album=somePictures2 This list is about 3000 links. Each album may have 500 or more...
7
by: rahismailbox | last post by:
I need to run a script in every 10 seconds in background of the site of 10-15 php pages. So how do i activate that script? Is there a code to be embedded in every php page so that the script got...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.