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.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
cron job problem (need help plz)
Old 05-25-2009, 04:59 AM cron job problem (need help plz)
Skilled Talker

Posts: 97
Trades: 0
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.
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 ("<br><br>Error in executing Cron file");
   }
 else 
  { 
// if it Doesn't exist, Create it then write command
  
touch($cron_file); // create the file, Directory "cron" must be writeable
  
chmod($cron_file0700); // 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 ("<br><br>Error in creating Cron file");

  }
}
?>
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 in executing Cron file") appears.. so i found that the error is in the execute line
could u plz help me in solving this problem
plz take a look on these 2 links:
http://www.queen-of-nile.com/cron/cron.php --> this is the page that creates the cron job file and when wirting exec it shows the die error
http://www.queen-of-nile.com/cron/test.php --> shows the sever details
plz i need help in solving this problem , if anyone can help me or send for me full example of creating cron job from php file
john_zakaria is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-26-2009, 03:21 AM Re: cron job problem (need help plz)
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
I'd say there's a 99% chance that cron (and most likely even exec) is disabled. I could be wrong in your case, but many hosts have this disabled.

Beyond that, I think you might be going about this wrong. I'm pretty sure cron jobs aren't set up like that.

If you're running in cPanel (which you should be. It's the only decent web manager IMO) you should be able to set up cron jobs from there. I'd check it out.
__________________
Will Anderson

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
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Old 05-26-2009, 04:43 AM Re: cron job problem (need help plz)
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
besides running cron jobs from PHP is a really really bad idea.

http://thedailywtf.com/Articles/Not-...-Cron-Job.aspx
__________________

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

willcode4beer is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to cron job problem (need help plz)
 

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 0.11987 seconds with 12 queries