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

  • SEARCH
  • Home
  • 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 6778389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:15:38+00:00 2026-05-26T16:15:38+00:00

I’m trying to write a PHP script that will allow the user to choose

  • 0

I’m trying to write a PHP script that will allow the user to choose both a time interval and number of iterations for running a task. I would prefer not to just leave the PHP script open for the whole time. I’m running Ubuntu, so I’ve looked at Cron and figured out how to start a job from PHP, but I’m not sure how to stop it after it has run the required amount of times. Any ideas?

  • 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-26T16:15:39+00:00Added an answer on May 26, 2026 at 4:15 pm

    Your cron would simply read a DB driven queue for these requests.

    So supposing the user selected a task and said at midnight, run 3 times, your php script would insert that request in a queue for the cron to check – say every minute. You could insert each iteration as a separate queue item or have the iterations as a column in the DB…

    ------------------------------------------
    | id | task | datetime | intval | status |
    ------------------------------------------
    

    and say a row looks like this:

    -------------------------------------------------
    | 1  | foo  | 2011-11-03 00:00:00 | 3 | pending |
    -------------------------------------------------
    

    every minute your cron would search the DB for tasks with a status of “pending” and also is scheduled for this datetime then loop through the results and do something like so…

    foreach($result AS $task)
    {
        for($i = 0; $i < $task->intval; $i ++)
        {
            $task->task();
        }
        mysql_query("UPDATE `table` SET `status` = 'complete' WHERE `id` = ".$task->id);
        // obviously put real mysql syntax here. I'm used to frameworks 
        // and forget the right raw way to do it
    }
    

    this also assumes task is a defined function. If not, then you fill in the blanks since we don’t know exactly what you’re doing.

    SO
    In order to achieve what you wanted in the comment below you would have your post script call the cron immediately upon inserting into the database – AND if you have a large user base or expect the queue to be populated then you would add a method that pretty much forces the item to the front of the cron or bypasses the queue entirely.

    The general idea here is that your options are so vast in this case that it is up to you to decide HOW to handle the requests and data. For example, you could store a serialized array of the user’s parameters…

    array('duration' => 5, 'loop' => 3, 'start' => '2011-11-03 00:00:00')
    

    then have your cron use the contents of this array to decide how to push the requests. You don’t need to limit it to one cron too. You can have one nearly continuously running – like every 10 seconds – that just grabs the next request and does it.

    So from me, the answer I have is vague in that I would definitely use crons to do this. NOT leave a script running on the client side cause that can be really bad.
    But cron jobs are just like all PHP. You likely need shell access to set one up, but in the end it’s just a server task that calls a script on your server every x seconds or at a certain time regularly.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.