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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:03:33+00:00 2026-06-06T01:03:33+00:00

<?php while(true){ //code goes here….. } ?> I want to make a PHP web

  • 0
<?php
 while(true){
 //code goes here.....
 }
  ?>

I want to make a PHP web server, so how can I make this script run forever with Curl?

  • 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-06T01:03:35+00:00Added an answer on June 6, 2026 at 1:03 am

    Don’t forget to set maximum execution time to infinite(0).

    Better make sure you don’t run more than one instance, if that’s your intention:

    ignore_user_abort(true);//if caller closes the connection (if initiating with cURL from another PHP, this allows you to end the calling PHP script without ending this one)
    set_time_limit(0);
    
    $hLock=fopen(__FILE__.".lock", "w+");
    if(!flock($hLock, LOCK_EX | LOCK_NB))
        die("Already running. Exiting...");
    
    while(true)
    {
    
        //avoid CPU exhaustion, adjust as necessary
        usleep(2000);//0.002 seconds
    }
    
    flock($hLock, LOCK_UN);
    fclose($hLock);
    unlink(__FILE__.".lock");
    

    If in CLI mode, just run the file.

    If in another PHP on a webserver, you could start the one which must run infinetely like this (instead of using cURL, this eliminating a dependency):

    $cx=stream_context_create(
        array(
            "http"=>array(
                "timeout" => 1, //at least PHP 5.2.1
                "ignore_errors" => true
            )
        )
    );
    @file_get_contents("http://localhost/infinite_loop.php", false, $cx);
    

    Or you could start from linux cron using wget like this:

    `* * * * * wget -O - http://localhost/infinite_loop.php`
    

    Or you could start from Windows Scheduler using bitsadmin running a .bat file which contains this:

    bitsadmin /create infiniteloop
    bitsadmin /addfile infiniteloop http://localhost/infinite_loop.php
    bitsadmin /resume infiniteloop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have this PHP code : <?php set_time_limit(0); //mysql connection while(true) { //check
i want to run a php program constantly in the server which would download
I have this code: protected void onHandleIntent(Intent intent) { while (true){ long endTime =
I have these code: <?php $i=0; while (true): echo test; $i<4 ? $i++ :
How would I execute a shell script from PHP while giving constant/live feedback to
I'm receiving this PHP error while trying to use the Normalizer class, specifically the
my question is pretty simple: can PHP and Java communicate, while PHP being the
So, i'm working on a progress bar for a CSV processing script. dnc_scrubber.php goes
Here's my code: <?php $sock = fsockopen(localhost, 6667); fwrite($sock, NICK PHP_thang\r\n); fwrite($sock, USER fikeh
Here's a small sample of some test code that simply goes to http://www.un.org/apps/news/story.asp?NewsID=37180&Cr=Haiti&Cr1= and

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.