Current location: Hot Scripts Forums » Programming Languages » PHP » cron job


cron job

Reply
  #1 (permalink)  
Old 04-28-09, 02:51 AM
john_zakaria john_zakaria is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
cron job

Good morning everyone
plz i want to know how to create a cron job using php function and also how to stop this cron from working using php...
all that i need is to create a cron job using php and when the administrator press send -> the cron will be execute
and when he press stop -> the cron will be deleted from cpanel

note that: the administrator does not have an access to the cpanel and also if he has .. he can not deal with it.

so can anyone have a function to creeate a cron job using php? and also stop it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-28-09, 09:07 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-29-09, 01:53 AM
john_zakaria john_zakaria is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by End User View Post
PHP Code:

<?

    crontab_set
('*','*','*','*','*');
function 
crontab_set ($min$hour$monthDay$monthNum$weekDay)

    
$command "$min $hour $monthDay $monthNum $weekDay /usr/local/bin/php -f /home/egypthol/public_html/snd2.php";
    
                                                         
    
//echo $command;
    
$cron_file "Feed_cron"
    
    
// check for cron/Feed_cron file. If it doesn't exist create it.
    // you must create the file from the browser to associate the proper group
    
if (file_exists($cron_file))
        {  
// if it exists, write new command
        
        
        
$open fopen($cron_file"w"); // This overwrites current line
        
fwrite($open$command);
        
fclose($open);
        
        
// this will reinstate your Cron job
        
        
exec("crontab /home/egypthol/public_html/cron/Feed_cron") or die ("Error");
        
        }
 else 

        { 
// if it Doesn't exist, Create it then write command
        
touch($cron_file); // create the file, Directory "cron" must be writeable
        
chmod($cron_file0777); // make new file writeable
        
        
$open fopen($cron_file"w");
        
fwrite($open$command);
        
fclose($open);
        
        
// start the cron job!
        
exec("crontab /home/egypthol/public_html/cron/Feed_cron"
or die (
"Error");



        }

}
?>
this is my code... and it makes the file Feed_cron and make inside it the commad

but there is an error in the exec line coz when the page is loaded the die message ("error") appears.. so i found that the error is in the execute line

could u plz help me in solving this problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-30-09, 10:20 PM
Software Development Software Development is offline
New Member
 
Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
crontab /home/egypthol/public_html/cron/Feed_cron

Set this in your web site control panel...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-03-09, 03:00 AM
john_zakaria john_zakaria is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Software Development View Post
crontab /home/egypthol/public_html/cron/Feed_cron

Set this in your web site control panel...
ok but how?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-03-09, 11:09 AM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
If you use cPanel or similar for your web control panel, there should be an option for adding Cron Jobs there?
__________________
Always sanitise your data


Best regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 05-04-09, 01:29 AM
john_zakaria john_zakaria is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by landing View Post
If you use cPanel or similar for your web control panel, there should be an option for adding Cron Jobs there?
i want to make the cron job using code because the administrator can not use the cpanel or unnderstand how it works and also he dont have the right to enter to the cpanel and modify it.... so he want me to do the cron job using code without the need to know cpanel (i mean the administrator)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job problem with php Keyne PHP 11 10-25-08 12:19 AM
CRON JOB with php file Jay6390 PHP 8 06-24-07 03:05 PM
Cron job problem sujata_ghosh Perl 3 12-08-06 03:03 AM
Cron Job raji20 Web Servers 2 10-25-06 08:14 AM
Cron Job Error Tempestshade PHP 6 09-10-04 06:10 PM


All times are GMT -5. The time now is 01:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.