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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:37:19+00:00 2026-05-31T17:37:19+00:00

I have a php script I need to run every 5 seconds (run, wait

  • 0

I have a php script I need to run every 5 seconds (run, wait until it’s done, wait 5 seconds, run again)

I have two ways of doing it. either have an infinte loop in the script with a sleep function that would look like that:

while (1)
{
   do_stuff();
   sleep 5;
}

or have bash script that will run the script and wait for 5 seconds. It would look like that

while [ 1 ]; do
    php script.php &
    wait
    sleep 5
done

I was wondering what is the most efficient way to do it.

The php script i am running is a codeigniter controller that does a lot of database calls..

  • 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-31T17:37:20+00:00Added an answer on May 31, 2026 at 5:37 pm

    If you’re doing a lot of DB calls, then do the sleep within php. That way you’re not paying the php startup penalty, the connect-to-the-db penalty, etc… that’l be incurred if you’re sleeping in bash.

    When you do the bash loop, you’ll be starting/running/exiting your script each iteration, and that overhead adds up quickly on long-running scripts.

    On the other hand, at least you’ll start with a “clean” environment each time, and won’t have to worry about memory leaks within your script. You may want to combine both, so that you loop/sleep within PHP (say) 100 times, then exit and loop around in Bash.

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

Sidebar

Related Questions

I have a php script I need to run frequently, ie approx every 10
I have a PHP script that I need to run every minute. I have
I have two php scripts that need to be run as continuous back ground
I have some php script that I would like to run on EVERY row
I have a php script I want to run every minute to see if
I need to run a php script as daemon process (wait for instructions and
I have a PHP script with infinite loop. I need this script running forever.
i have a problem, i'm working on a gallery php script and need help,
I would like run a PHP script that runs every second to update a
I have installed localhost/server in my machine and I need to run a php

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.