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 6718327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:57:22+00:00 2026-05-26T08:57:22+00:00

I am working on a scraping project, somewhere in the application I need this

  • 0

I am working on a scraping project, somewhere in the application I need this functionality

run a script again and again with a pause of some seconds.

I tried to use pcntl to accomplish the job. so wrote this script

/************************/
$intra_sleep=10; // we're going to set the intra process launch sleep at 10 seconds
$task_process=null; // by default this is set to null -- do nothing
$loop_limit=0; // this is the number of times the loop shoul run -- if set to -1 look infinite number of times

if (isset($argv[1])) $task_process=$argv[1];
if (isset($argv[2])) $intra_sleep=$argv[2];
if (isset($argv[3])) $loop_limit=$argv[3];


for ($loop_count=0; $loop_limit==-1 ? true : $loop_count< $loop_limit; $loop_count++) 
{
  $pid= pcntl_fork();

   if ($pid == -1) 
   {
    die('MASTER: could not fork');
   } 
   else if ($pid==0) 
   {
     if ($task_process) 
     { 
       echo "Sleeping for  $intra_sleep Seconds\n"; 
       sleep($intra_sleep);
       echo "Launching Child \n\n"; 
       exec($task_process); // from here process script is being launched
     } 
     else 
     {
    echo "  CLONE: no task process defined -- doing nothing " . PHP_EOL;
     }
  } 
  else 
  {
     pcntl_waitpid($pid,$status);  
  } 


}

/*********************/

I am calling this script from CLI like this way

nohup php /this/script.php "php /path/to/process.php" 10 -1

I expect that process.php will be launched again and again with 10 seconds intervals. It was doing work what I was expecting, but when I check runing processes, there were thousands processed running, launched by this script.

My requirement is very simple: a script should be launched again and again with 10 second Pause.

  • 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-26T08:57:22+00:00Added an answer on May 26, 2026 at 8:57 am

    If you just want to repeat a PHP script every x seconds, then you could use The Fat Controller to handle all the daemonising and running of scripts for you so you can concentrate on business logicin your PHP script. It’s written in C so it’s very stable, no matter what you do in your PHP scripts.

    It basically provides the following functionality:

    • daemonising, so you don’t have to mess about with nohup)
    • multitasking, in your case not relevant so you just set concurrent processes to 1
    • repeated running, so you don’t have to mess about with forking.

    There’s lots of functionality to handle errors in PHP scripts and erroneous long running scripts.

    It’s pretty easy to install and get set up and there’s plenty of documentation on the website to get you started. It’s worth a quick look at least to see if it will help you.

    http://fat-controller.sourceforge.net/

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

Sidebar

Related Questions

I'm working on some screen scraping software and have run into an issue with
I am working on some scraping app, i wanted to try to get it
I am working on upgrades to a screen scraping application. We are using an
I'm working on a C# application that needs to scrape some data from a
currently im making some web scraping script. and i was choice PAMIE to use
I'm working on a project which involves scraping from the major search engines (to
I am working on a data-mining project for which I need to analyse the
I am working on a web-scraping project. One of the websites I am working
I'm working on a small project which will basically do some Facebook stuff and
I've recently been writing some code for a research project that I'm working on,

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.