Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Website and Server Administration Forum


You are currently viewing our Website and Server Administration Forum as a guest. Please register to participate.
Login



Reply
crontab to php a file isnt working!
Old 04-22-2010, 10:42 AM crontab to php a file isnt working!
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi guys,

I have a php file in
/var/www/html/rss_feeder.php

This file basically looks at a DB and writes an rss feed to feed.rss

if i do this:

lynxus@blaa# php /var/www/html/rss_feeder.php

It works and updates the file.

However when i put a cronjob in for every 1 minute it doesnt seem to do it.
The script isnt dying and cron isnt showing any errors.

Any ideas what could cause this?

Ive played with permissions and nothing, Ive touched the file and nothing ive left it not there and nothing.

crontab -l

0-59 * * * * php /var/www/html/cron_feeder.php -> /dev/null


Any ideaS?

The cron log shows its doing (cmd) php /var/www/html/cron_feeder.php


Im really quite stumped here.

Thanks to anyone who can help.

-G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 04-22-2010, 10:49 AM Re: crontab to php a file isnt working!
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Oh godamnit ive figured it out.

the php file didnt have teh absolute path to the output file, So when root ran the crontab the file ended up in ~root

Grr
lol
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-23-2010, 02:57 AM Re: crontab to php a file isnt working!
casius's Avatar
Super Talker

Posts: 129
Trades: 0
Hello,

Promising solution is to include the script in one of the pages of the site, for example the very first: “index.php”. (<? include “cron.php”; ?>)
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
casius is offline
Reply With Quote
View Public Profile
 
Old 01-31-2011, 06:03 AM Re: crontab to php a file isnt working!
miki86's Avatar
Extreme Talker

Posts: 185
Location: print_r($serbia);
Trades: 0
Hi,

I need a little help.
I can't get my crontab to work.

My php script is working ok i tested it, looking at the cron log file i see that it runs the script but nothing happens.
It's like it doesn't recognize it as PHP file.

my crontab:
Code:
00 12 * * * /var/www/cron/dayupdate.php
cron log file:
Code:
Jan 31 02:56:01 server crond[5154]: (root) CMD (/var/www/cron/dayupdate.php)
I read somewhere that my first line in php should be #!/usr/bin/php but it doesn't work that way either.

Any suggestions?
miki86 is offline
Reply With Quote
View Public Profile
 
Old 01-31-2011, 06:23 AM Re: crontab to php a file isnt working!
miki86's Avatar
Extreme Talker

Posts: 185
Location: print_r($serbia);
Trades: 0
Never mind i solved it, same problem as lynxus had, needs to be absolute path in php file.
miki86 is offline
Reply With Quote
View Public Profile
 
Old 02-01-2011, 11:35 AM Re: crontab to php a file isnt working!
Novice Talker

Posts: 13
Name: Tom
Trades: 0
Indeed, the full path to the php binary is necessary for it to work
I also spent some time figuring that out several years back
serverboost is offline
Reply With Quote
View Public Profile Visit serverboost's homepage!
 
Old 02-01-2011, 03:22 PM Re: crontab to php a file isnt working!
miki86's Avatar
Extreme Talker

Posts: 185
Location: print_r($serbia);
Trades: 0
No need for php binary it's working ok like lynxus wrote.

Code:
0-59 * * * * php /var/www/html/cron_feeder.php -> /dev/null
But, inside that cron_feeder.php paths need to be absolute (full path to the file).

I see that file containing cron jobs is located in /var/spool/cron.
Is there a way to change that path, not for root user but for others?
miki86 is offline
Reply With Quote
View Public Profile
 
Old 02-01-2011, 03:29 PM Re: crontab to php a file isnt working!
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Glad to see the thread helped

And yeah. This is something that catches me out from time to time.

I spend a lot of time looking at permissions to finally remember that an absolute path is missing. ( crontabs esp are a pain for this issue )

Certainly no need to worry about the binary locations..
But just when you use some form of path in the script ( like file.php ) you need the full path like ( /var/www/html/somedir/file.php ) otherwise it will just look in the folder where it was run from

Ie: as root.. ( a crontabbed root )
it would look in /home/root/file.php rather than /var/www/html/somedir/file.php )

Very annoying.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 02-01-2011, 03:32 PM Re: crontab to php a file isnt working!
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Quote:
Originally Posted by miki86 View Post
No need for php binary it's working ok like lynxus wrote.

Code:
0-59 * * * * php /var/www/html/cron_feeder.php -> /dev/null
But, inside that cron_feeder.php paths need to be absolute (full path to the file).

I see that file containing cron jobs is located in /var/spool/cron.
Is there a way to change that path, not for root user but for others?

I suppose you could write a bash script that chdirs to the correct path and then executes the php in that location..

Just that just makes things complicated.. Better just to have absolute paths.
( Maybe add a file called paths.php to the same place as the file execution ) and have your paths in there

At least if you change servers and the paths change, You can quickly get ALL scripts working again
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 02-01-2011, 03:41 PM Re: crontab to php a file isnt working!
miki86's Avatar
Extreme Talker

Posts: 185
Location: print_r($serbia);
Trades: 0
That's true i agree but im planing to create a dynamic cron job adding to that file, and i dont like stuff like that in place where my root things are.
My webserver user doesnt have access outside web dir.

Im looking at the webmin crontab configuration right now and i see that working directory can be changed, im just trying to figure out which file contains that configuration.

Thats the best i could think of, in that case i avoid using db to much and i need timed events, if you have something in mind please share.

Thank you.
miki86 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to crontab to php a file isnt working!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.00302 seconds with 12 queries