Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4582640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:06:13+00:00 2026-05-21T21:06:13+00:00

I want to create cron jobs from within PHP, a bit like in cPanel

  • 0

I want to create cron jobs from within PHP, a bit like in cPanel or Plesk but I’m stuck. I want to do this programatically and not force the user to go to cPanel to create the crons manually…..

Tried many things, read many things… including here on stackoverflow, nothing works.
I try editing crontab from php like shell_exec(‘crontab /pathtomycronfile/cron.txt’) and then editing the cron file itself but it doesn’t work. User is ‘apache’ and I tried setting the crontab for apache .. doesnt’t work either …

Please can anyone help with this? Have you been able to create cron jobs from php before?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:06:14+00:00Added an answer on May 21, 2026 at 9:06 pm

    Under some *nix systems, crontab will store each user-specific cron file in e.g. /var/spool/cron/crontabs/[USERNAME] . They’re not intended to be edited directly, but you could get PHP to do so.

    You might also need to change the permissions on the containing directory, so that PHP can see the file to edit it. You could then do so with e.g:

    <?php
    $user = get_current_user();
    $cron_file = fopen("/var/spool/crontabs/$user", "a");
    fwrite($cron_file, "\n* * * * * touch /tmp/testcron\n");
    fclose($cron_file);
    

    To be honest, though, this is very dangerous. Instead, you should consider having a cron.php, which gets called every 15 minutes, and put all your logic about what actual tasks should be carried out at a given quarter-hour in that cron.php. Don’t edit the crontab to put the logic in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to call a cron job from within a PHP script. I
I want to make a news portal(php) with minimum mysql force. :create a cron,
I'd like to create a php script that runs as a daily cron. What
I want to create my Rails application with MySQL, because I like it so
I want to create cron job that runs a script every 5 seconds. Seeing
Hi I want to run a cron job to call a PHP script on
I am using Zend Framework 1.9.6. I want to start using cron jobs. I
I want create a DataSet class which is basically a list of samples. But
In my Zend framework Project I want to create a Cron Job . I.e.,
I am writing a series of cron jobs. I want each task to log

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.