0

I wrote a script that exports data from database and then put it to XML file. Script works in infinite while loop with proper break statement (after task is done). Task takes to 10 minuts. When I make http request to start a job, browser which i'm using completly freezes - not only requested URL but whole host. In the same time with other browsers I can browse the webpage which contains my script.

Snippet of my PHP script:

while(true)
{
    if($i === $z)
    {
        break;
    }

    foreach((array)$this->project as $project)
    {
        makeYourJob();
        usleep(1000000);
        $z++;
    }
    usleep(2000000);
}

Script is invoked with this jquery code (I type address of HTML page which contains this code):

    $.get("cron.php");

Also I tried to type cron.php in URL bar and browser hangs up too. Why browser which runs the script freezes? How to avoid this?

EDIT: Making a simple get/post request by ajax or user will not resolve problem. This post isn't a duplicate. Here is a solution:

exec("wget http://www.domain.com/scrip_name.php > /dev/null &");
webrama.pl
  • 1,870
  • 1
  • 23
  • 36

1 Answers1

0

Clearly, the if statement which breaks the infinite loop is not being invoked.

Can you check the initialization values of $i and $z? Also, === checks if the 2 variables are of the same type AND of the same value. I'd suggest you check the type of $i and $z variables.

Arpit
  • 440
  • 3
  • 7