Hi,

I have a php script which has a while(true) loop that runs indefinitely writing data to an output stream.

I want to be able to call this php script and let it run forever, through a browser, without anything timing out. It seems to work right now, except one thing that annoys me. Firebug still shows the request as "loading" (the GET has the load bar next to it) will the server ever timeout the script?

What is the best way to do this?

BTW. it is not really an infinite loop... I use sockets to have other scripts communicate with each other whilst running

... so I can call "stopservice.php" and that script will use sockets within the local server to tell the stream script to stop.

    I wonder if Firebug would still claim something is loading if you run that script asynchronously.. like using AJAX or something. That's my only idea.

      Technically as long as the server sends info to the browser every 30 seconds or so, the script shouldn't timeout.

      Then again, technically you're limited by how long a PHP file can execute 😉 If it's set to like 30 seconds, then it will timeout. There are ways to get around that (I believe) but I'm not exactly sure how, and I'd rather not have my computer die on me.... again today.

      As long as the server hasn't sent the "200 OK" response to the browser, Firebug should still show as loading because technically the page is still executing. But if you do send the "200 OK" response, I'm pretty sure you'd have to use JS to display that output because the document is "finished" once it gets the "OK" response.

      AJAX would be the proper way to go here. I can't see doing it through straight PHP.

      Oh!! And yes, Firebug will still show it as loading because Firebug watches all NET calls performed by the page and times them. It's a nifty extension to FF that all web devs should have.

        Oh ... I am already using AJAX to request it asynchronously. Even with asynchronous requests you can still monitor them in firebug.

        as for php timing out ... i set the set_time_out(30) function so it basically extends the running time every time it loops ... allowing the function to keep going indefinitely.

        Would the server time out php itself???

        I guess I should just echo the HTTP 202 okay header then ... that should satisfy it correct?

          Well, if you're using AJAX, then really your page should be loading fine (i.e. the progress bar in firefox goes away). If that's true, then the 200 response is being sent.

          The issue is that you are trying to stop something that Firebug is designed to do: look at the requests sent from each page. So in order to stop that "annoyance" all you have to do is disable firebug for that site.

          FireBug will always show a loading icon in its "window" when any request is being sent. Until that request is finished (i.e. all data has flowed from server to user) the loading icon will appear. It's a built-in feature of FireBug and can-not be worked around.

            The thing is, All I want to do is send the request to start the script. I don't actually care about the script finishing, It should just run forever on the server side. How does firebug determine that a GET request is complete ... that's all I want to know.

            I know it doesn't really matter, but just out of curiosity and for future reference how DOES firebug determine that a script is fully loaded?? Is this determined by the HTTP header or what??

              It determines it's complete by the response that it receives (same as any browser). The difference between FireBug and the browser is that FIrebug looks at all requests (Javascript, or CSS / HTML / CF / Embedded elements) not just the singular HTML page requested (index.php or download.html).

              If you really want your stuff to run indefinitely, just use a [man]shell_exec/man on teh page and don't capture the output. Use the php command to execute your script. If you're not actually flowing any data to the user, I'd suggest using a Cron Job or "Service" to complete the task.

                not that I'd recommend you'd use this, the Cron Job is probably your best bet, but the PHP code to extend server execution time is
                ini_set('max_execution_time', 'timeinseconds');

                  yes, but that's not the issue. The issue is that he wants a plugin in his browser to stop showing a loading sign. The only ways to do that are outlined in previous posts.

                    Write a Reply...