icon Learn how to get the most out of Surmunity - read our forum tips here! | Welcome! Please register to access all of our features.
Old April 27th, 2008, 3:53 AM   #1 (permalink)
Registered User
Seasoned Poster
 
Joined in Feb 2008
Lives in Kingdom Of Saudi Arabia
Hosted on i have my own server :)
35 posts
Gave thanks: 1
Thanked 3 times
how can i make php files run in cron jobs?

Hi all

i wrote this code to delete all files that last accessed was after 1 hour ..

it works great if i run the file manually from the browser but it doesn't if i use cron jobs !

i don't know if there is some rules or something ..

PHP Code:
<?
function cleantmp() {
 
$seconds_old 60*60;
$directory "/home/***/public_html/temp";
if( !
$dirhandle = @opendir($directory) )
return;
 
while( 
false !== ($filename readdir($dirhandle)) ) {
if( 
$filename != "." && $filename != ".." && $filename !=".htaccess" ) {
 
$filename $directory"/"$filename;
 
if( @
filemtime($filename) < (time()-$seconds_old) )
 @
unlink($filename);
 }
 }
 }
cleantmp();
?>
so how can i make it works with cron jobs?
thx all
vAMP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 27th, 2008, 8:43 AM   #2 (permalink)
Surpass Fan
Excelling Contributor
 
cowboy's Avatar
 
Joined in Nov 2005
Lives in Colorado
Hosted on DEDI
921 posts
Gave thanks: 2
Thanked 91 times
Cron format for php file:

php /path/to/file/and/name

I would suggest placing it above the public_html directory so it cannot be run from a browser, so your command would be:

php /home/***/name_of_file.php
__________________
Where would you be if you were at the highest court in the land (US)?
cowboy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 27th, 2008, 8:50 AM   #3 (permalink)
Registered User
Seasoned Poster
 
Joined in Feb 2008
Lives in Kingdom Of Saudi Arabia
Hosted on i have my own server :)
35 posts
Gave thanks: 1
Thanked 3 times
thx

i was using /usr/local/bin/php /home/***/public_html/clean.php

i will try to use php only

10x again for ur help
vAMP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 27th, 2008, 8:56 AM   #4 (permalink)
Registered User
Seasoned Poster
 
Joined in Feb 2008
Lives in Kingdom Of Saudi Arabia
Hosted on i have my own server :)
35 posts
Gave thanks: 1
Thanked 3 times
it doesn't work
vAMP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 27th, 2008, 9:14 AM   #5 (permalink)
Surpass Fan
Excelling Contributor
 
cowboy's Avatar
 
Joined in Nov 2005
Lives in Colorado
Hosted on DEDI
921 posts
Gave thanks: 2
Thanked 91 times
Have support take a look at your server setup.
__________________
Where would you be if you were at the highest court in the land (US)?
cowboy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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