The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Run a cron job which running time is decided by another PHP page

Discussion in 'General Discussion' started by red whale, Dec 21, 2015.

  1. red whale

    red whale Registered

    Joined:
    Dec 21, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    cPanel provides the cron job setting interface. You can add the time you'd want to run the command. However, you can just only add the unvaried value of time and cannot make it flexible (Such as make the running time decided by another PHP page) So how can I use cPanel to add a flexible time?

    P.S. I can't use exec or system function to achieve it, because the server administrator doesn't allow me to use these two functions due to the security reasons. The only way I can do is to add the cron job time via the cPanel.
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,683
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Could you provide a specific example of how you want flexible time implemented? For instance, do you want the time the cron job runs to automatically change based on certain variables? If so, you may need to build that functionality into the custom script itself.

    Thank you.
     
  3. red whale

    red whale Registered

    Joined:
    Dec 21, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hello

    Thanks for your response

    I hope the running time of the cron job can be decided by another PHP script which is on my website. For example, I can let the user inputs the time on the form whenever they want. After submitting the form, create a cron job which running time is based on the form the user has filled. Suppose the user input the time "37 1 20 12 0" and the target "/home/username/public_html/mail.php". After submitting the data, sending a mail on 12/20 at 1:37 automatically.

    The point confuse me is that “how to build that functionality into the custom script itself?” I can't use exec and system function in PHP and that's why I need to create the cron job(s) only via cPanel. But cPanel can only add the unvaried running time manually. So that's is the problem I want to solve.

    Thank you.
     
  4. linux4me2

    linux4me2 Well-Known Member

    Joined:
    Aug 21, 2015
    Messages:
    79
    Likes Received:
    13
    Trophy Points:
    8
    Location:
    USA
    cPanel Access Level:
    Root Administrator
    You could create a database to hold all the mail times saved by your users. When your users submit the form with the time and other data, you save it to the database. Set up a cron job through cPanel that runs a PHP script that checks the database for any emails that are due to be sent, and sends those that are due. You can run the cron job linked to your PHP script as frequently as you need to--even every minute if your web host allows it--to execute the script and send the emails.
     
Loading...

Share This Page