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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:21:44+00:00 2026-06-03T06:21:44+00:00

How to create unstoppable while loop, if it’s already running dont run it again,

  • 0

How to create unstoppable while loop,
if it’s already running dont run it again, I assume that if script running it will update last cron time in database, and script will check if current time – 40 seconds is less than last cron time. Sample of what I’ve, but that’s overlooping ( running again and again do process ) Thanks!

<?php
ignore_user_abort(1); // run script in background 
set_time_limit(0);    // set limit to 0


function processing()
{
//some function here
setting::write('cron_last_time', $time); // write cron last time to database
}

$time = current_timestamp();  // current time
$time_before = $time - 20;   //

$settings = setting::read('module_cron_email'); // Get last cron time from database ( in array )
$time_last = $settings['setting_value'];     // Last cron time get value from array



if ($time_before < $time_last) // check if time before is less than last cron time
{ 
   do{
   processing(); //run our function
   sleep(7);    // pause for 7 seconds
   continue;   // continue
   }
   while(true); // loop
}else{

echo "already running";
die();
}
?> 
  • 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-06-03T06:21:46+00:00Added an answer on June 3, 2026 at 6:21 am

    When starting the script, check for a lock file. If it does exist, quit or skip the loop. If it doesn’t exist, create the file and let it run.

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

Sidebar

Related Questions

Create Pex test to test a DLL and hardware controlled by that DLL? I
// Create a scanner that reads from the input stream passed to us CSLexer
CREATE TRIGGER dbo.YourTrigger ON a AFTER UPDATE AS BEGIN SET NOCOUNT ON; IF NOT
CREATE TRIGGER dbo.updateTrigger ON dbo.Education AFTER UPDATE AS BEGIN SET NOCOUNT ON; IF NOT
Create an array class for Employee which will reserved 7 elements. The class will
I want to create a unstoppable service, i.e if the user clicks the Force
//Create an album $album_details = array( 'message'=> 'How will you die?', 'name'=> 'How will
CREATE TRIGGER `lastedited` AFTER UPDATE ON `eng-jap` FOR EACH ROW BEGIN UPDATE `mrhowtos_main`.`eng` SET
Create Proc CrearNuevoAnuncio @Titulo varchar(250), @Precio int, @Descripcion varchar(250), @IDCategoria int, @IDImagen int, @Login
create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't

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.