PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Ok, I'm not sure if this is even possible... But I want to output dots the the browser for as long as one of the functions (whois lookup) keeps loading (which is usually over 30 seconds).
// Reset counters
$timeoutcounter = 0;
$retrycounter = 0;
while (empty($isavail)) // If isavail is empty, the WHOIS has not yet been completed
{
echo "LOOP #$timeoutcounter ";//REMOVE - FOR TESTING ONLY
// If 5 seconds elapsed, send a dot (or any other character)
if ($timeoutcounter == 5)
{
echo ". <br>Available: $isavail <br>Retry: $retrycounter <br>Domain: $fulldomain<br>";
$timeoutcounter = 0;
}
// Send the WHOIS after x seconds
if ($retrycounter == 1)
{
// start buffering the output
ob_start();
include ("whois.inc");
$whoisresult = lookup($fulldomain);
while (empty($isavail))
{
// Check if domain is available
$isavail = $whoisresult[0]; // Contains "1" is it's available, blank if it's registered
echo "<br>CHECK COMPLETE: $isavail <br> Result: $whoisresult[0]<br>";//REMOVE - FOR TESTING ONLY
}
// Flush buffer once loop has been broken
ob_flush();
flush();
}
// Get WHOIS result
$isavail = $whoisresult[0]; // Contains "1" is it's available, blank if it's registered
// Timeout executing
sleep(1);
// Increase counter
$timeoutcounter++;
$retrycounter++;
}
I've been scrapping and re-coding all day and I just can't figure it out... What happens now is this:
Gelieve te wachten terwijl we de beschikbaarheid van uw domein controleren ...LOOP #0 LOOP #1
So it loops until the function starts loading, and then it waits until the loading is complete before doing anything else instead of repeating the loop until the buffer can be sent (which is when the WHOIS is done).
It cannot be done using php alone, as it is not a multi-threaded language. However, you could use a javascript function, or an iframe.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Jenk wrote:Or do what some websites do and load a GIF of a knight rider esque bar in a second window and close it after a set time
as far as I know that's also javascript (along with META tags I suppose).... PHP alone cannot control how the page behave after it's generated. What you need is client side scripting with javascript.
interesting class. i'll have to play around with it.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
By the way, in case I'd do it with Javascript, would that keep the browser open? Because if it doesn't receive anything within 30 seconds it always stops loading... Just wondering about this as I'll probably try the PHP-only solution first.
nutkenz wrote:By the way, in case I'd do it with Javascript, would that keep the browser open? Because if it doesn't receive anything within 30 seconds it always stops loading... Just wondering about this as I'll probably try the PHP-only solution first.
You can try XMLHTTPRequest object for dynamic updation without refresh. its cross-browser too.
Long time since I looked into this but this code (influenced from this board a long time ago, can't find the topic now though) may also help without using HTTPRequests...
after each change to the message you want to output.
Of course this doesn't solve the problem that a single php command can take a long time to process. Maybe javascript could help in this instance ( a timer calls the slUpdateSpan function) but unsure.
On a side note, If there is sufficient interest in this I will try to write a more descriptive topic with working examples.
Last edited by CoderGoblin on Wed Sep 21, 2005 6:56 am, edited 1 time in total.
I tried HV HTTP Multipart, but this doesn't work for PHP pages I think, it's only meant for HTML pages as far as I can tell. Either way, it completely broke the page.
CoderGoblin wrote:Of course this doesn't solve the problem that a single php command can take a long time to process
Well, it's mainly due to the .NL whois check, it just takes too long for that server to respond. Other domains are usually finished within 1 or 2 seconds, but this one can take over 30.
Does the Javascript above keep the browser alive? If not, I'll still be unable to get WHOIS checks which take 30+ seconds to work. By the way, I already tried using set_time_limit(600); in both the main page and the function itself. PHP safe mode is disabled and max_execution_time is also set to 600 so it must be the browser itself giving up?