pea Posted November 28, 2008 Share Posted November 28, 2008 Sorry about posting twice in a row . I'm looking to use cron for one of my apps which i'll be distrobuting, but i can't find any information about how to create a cron job using only php. Is it even possible? Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/ Share on other sites More sharing options...
.josh Posted November 28, 2008 Share Posted November 28, 2008 possibly with exec or shell_exec Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701009 Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 the normal way to edit the cron is with 'crontab -e', which opens the cron in a text editor. obviously, you can't do this with PHP exec(), but you can also do 'crontab filename' and it will install the contents of 'filename' as the new cron. So using PHP create a temporary file will all the cron info in it (not just new, old and new) then run 'crontab /path/to/file' via one of PHP's exec() functions Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701076 Share on other sites More sharing options...
pea Posted November 29, 2008 Author Share Posted November 29, 2008 Well that's easy. I'm not familiar with cron, i assume it's just a file with a list of schedules. Is there so way to return the contents of the file for me to write back? Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701658 Share on other sites More sharing options...
haku Posted November 29, 2008 Share Posted November 29, 2008 fread() Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701680 Share on other sites More sharing options...
rhodesa Posted November 29, 2008 Share Posted November 29, 2008 execute 'crontab -l' to get the current contents of the file. just search google for 'crontab' and there will be TONS of info on how the crontab is formated Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701682 Share on other sites More sharing options...
pea Posted November 29, 2008 Author Share Posted November 29, 2008 I don't think i have permission to do that, or i might as well use fwrite to add the cronjob. Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701691 Share on other sites More sharing options...
pea Posted November 29, 2008 Author Share Posted November 29, 2008 i've already tried crontab -l, but can't get any info. I'll do some more tests though. Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701693 Share on other sites More sharing options...
pea Posted November 29, 2008 Author Share Posted November 29, 2008 This forum really needs an edit option. Just for anyone else wanting to know the answer; Cronjobs were enabled but exec wasn't: <?php if(exec('crontab -l') == FALSE){ echo 'false'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701777 Share on other sites More sharing options...
.josh Posted November 29, 2008 Share Posted November 29, 2008 This forum really needs an edit option. You're allowed to make an edit up to like 2-3m after you post (don't remember exact window). But past that, we've disabled it, due to people constantly deleting posts and threads after the fact, or else going back later and editing and then it causes confusion in the whole problem solving process. Quote Link to comment https://forums.phpfreaks.com/topic/134630-creating-a-cron-job-with-php/#findComment-701793 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.