1

I have a script, lets call it linkchecker, that loops through about 10.000 URLs, checking them for http status codes. When they are checked, the url is marked as checked in my DB. It wont output anything until its done, which can take many hours.

So I thought about just having another script that will run the linkchecker in the background, while continually polling the DB about how many URLs are checked, so I can follow the progress, and if any URLs are giving a problem with long connection time and so on.

I tried just running the linkchecker in an iframe, but nothing will load until the linkchecker has finished.

How can i execute this linkchecker in the background while the main script runs normally, executing other tasks?

2
  • Fork it? Check Google ón how to dó it. Commented Dec 9, 2011 at 22:33
  • Um. Cronjobs spring to mind, here. max_execution_time would get in your way eventually, when running the script in an iframe. Commented Dec 9, 2011 at 22:35

3 Answers 3

2

You have to set a cron job (if you are running Linux) that executes a curl command to access a PHP script (external, like 'curl http://domain.com/php/something.php') or just executing a php command pointing to a internal file.

You can make a scheduler that executes every minute (that's the minimum execution time supported by cron job) and executes a "block" of your work. Of course, you must set PHP to skip the 30 seconds execution limit used by default.

Sign up to request clarification or add additional context in comments.

Comments

0

In the DB make a column you call "Checked". Just make the PHP-script update which are checked in the database. Use phpMyAdmin to see the database graphically, just choose to sort after the column "Checked" and then you could see how far it has come.

You have to do it this way, because the webpage will not update until the script is done. However you could make the script run another script that says how far the process is, but that would maybe be too time-consuming?

You also have to go into php.ini to check that max_execution_time is set to several hours. 60*60*24 = 1day = 86 400 seconds.

Hope this helps! :)

Comments

0

I suggest making an AJAX request to new page lets call it ajaxChecker.php

In thuis page its just see if there is unchecked URLs (return number) If the number of unchecked is zero then echo the output in the new div

function checker()
{
    $.post('ajaxChecker.php',function(data){
    if(data.length > 0)
    $('#result').html(data); 
    });
}

setInterval( "checker()", 10000 );

And of course make a request through ajax or cron job to start it first

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.