Webmaster Forum


Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 03-21-2012, 08:41 AM
Contributing Member
Latest Blog:
None

 
Join Date: 03-22-10
Posts: 63
iTrader: 0 / 0%
AJAX question

I have a script that queries several whois servers for 100 domain names. The querying is written in PHP.

I tried a lot of ways to show the results one by one as the whois servers answers, but I had no succes. Mainly I tried to use flush() and ob_flush() functions from php.

I read a lot of resources on the internet, and it seems that thw only way would be to use AJAX (though I never understood why flush() and ob_flush() didn't work).

So, two questions:
1. Why flush() is not working in php?
2. How can I use AJAX to get my results shown asynchronously?

Thanks
__________________
Free domain name generator
 
Reply With Quote
  #2 (permalink)  
Old 03-23-2012, 12:58 AM
JohnnyS's Avatar
Contributing Member
 
Join Date: 07-05-11
Location: philippines
Posts: 312
iTrader: 0 / 0%
can you post your code using ob_flush?
 
Reply With Quote
  #3 (permalink)  
Old 03-23-2012, 01:16 AM
Contributing Member
Latest Blog:
None

 
Join Date: 03-22-10
Posts: 63
iTrader: 0 / 0%
This is the main script:
Code:
echo '<table class="dtable">'; foreach (/* the list of domain names generated */){ $this->show_domain_availability($domainName); } echo '</table>';
This is the show_domain_availability function:

Code:
function show_domain_availability($domain){ if ($this->checkDomain($domain)){ echo "<tr><td>AVAILABLE</td></tr>"; }else{ echo "<tr><td>NOT AVAILABLE</td></tr>"; } ob_end_flush(); ob_flush(); flush(); ob_start(); }
This part with ob_flush() and flush() I tried in tens of ways as seen on the php forums and php.net meaning that I tried putting flush() several times instead of once. I tried filling the buffer. I even changed the output_buffering settings in php.ini. I tried everything that I have already found on php forums regarding this function.
__________________
Free domain name generator
 
Reply With Quote
  #4 (permalink)  
Old 03-23-2012, 02:29 AM
Super Moderator
Latest Blog:
None

 
Join Date: 11-11-11
Location: Copenhagen, Denmark
Posts: 1,853
iTrader: 0 / 0%
I don't believe you should use the ob_ functions in this context. If you remove
Code:
ob_end_flush(); ob_flush(); flush(); ob_start();
Does the script work at all? If not, what error does the script come up with?
__________________
Need a break? EnterCave more than 40000 online games in 15 categories.
Search or browse through EnterCave Online Games Directory
 
Reply With Quote
  #5 (permalink)  
Old 03-23-2012, 02:34 AM
Contributing Member
Latest Blog:
None

 
Join Date: 03-22-10
Posts: 63
iTrader: 0 / 0%
The script works but does not flush the output buffer. Meaning that it has no efect.
Please look in my signature. That's where the script runs. Try a domain name. Press check. Now you have to wait for several seconds in order to get all the output at once.
I would like to have the domains shown one by one as I get the results from the whois server.
__________________
Free domain name generator
 
Reply With Quote
  #6 (permalink)  
Old 03-23-2012, 04:46 AM
Super Moderator
Latest Blog:
None

 
Join Date: 11-11-11
Location: Copenhagen, Denmark
Posts: 1,853
iTrader: 0 / 0%
Here is an example you might want to play with, it uses javascript/ajax:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled</title> <style type="text/css"> table,td { border: 2px solid black; } </style> </head> <body> <table> <tr> <td id="dmnm1">domain.com</td> <td id="dmnm1avail">Looking up availability...</td> </tr> <tr> <td id="dmnm2">domain2.com</td> <td id="dmnm2avail">Looking up availability...</td> </tr> <tr> <td id="dmnm3">domain3.com</td> <td id="dmnm3avail">Looking up availability...</td> </tr> <tr> <td id="dmnm4">domain4.com</td> <td id="dmnm4avail">Looking up availability...</td> </tr> <tr> <td id="dmnm5">domain5.com</td> <td id="dmnm5avail">Looking up availability...</td> </tr> </table> <script type="text/javascript"> /* This is the url to the script there will check if the domain is available. The script needs to output for example Available or Unavailable, echo can be used for that. The output from the script will be added to table-cell next to the domain being checked. The domain is added as a parameter to the url eg: /test/avail.php?domain=thedomaintocheck.com */ var availSriptURL = "/test/avail.php"; function switchXHRState() { if(this.readyState == 4) { this.callback.apply(this, this.arguments); } } function loadFile (sURL, fCallback, argumentToPass1) { var oXHR = new XMLHttpRequest(); oXHR.callback = fCallback; oXHR.arguments = Array.prototype.slice.call(arguments, 2); oXHR.onreadystatechange = switchXHRState; oXHR.open("GET", sURL, true); oXHR.send(null); } function insertDomainAvailToPage(mNumber) { document.getElementById("dmnm" + mNumber + "avail").innerHTML = this.responseText; //if unavail is in the response, make text red if(document.getElementById("dmnm" + mNumber + "avail").innerHTML.toLowerCase().indexOf("unavail") > -1) { document.getElementById("dmnm" + mNumber + "avail").style.color = "red"; } } for(var a = 1; a != 101; a++) { if(typeof document.getElementById("dmnm" + a) != "undefined") { loadFile(availSriptURL + "?domain=" + document.getElementById("dmnm" + a).innerHTML, insertDomainAvailToPage, a); } else { break; } } </script> </body> </html>
It will make asynchron requests for the domains listed in the table, acording to the ids of the table-cells, i hope you can see where i am going with the script.


For testing i used this code as avail.php:
Code:
<?php $domain = $_GET["domain"]; if($domain == "domain2.com") { echo $domain." is available"; } else { echo $domain." is unavailable"; } ?>
It does not check if the domain is avaiable, but you will need to create a script there checks if the domain is available and output the text that the javascript will insert to the cell next to the domain.
__________________
Need a break? EnterCave more than 40000 online games in 15 categories.
Search or browse through EnterCave Online Games Directory
 
Reply With Quote
  #7 (permalink)  
Old 03-23-2012, 05:45 AM
Contributing Member
Latest Blog:
None

 
Join Date: 03-22-10
Posts: 63
iTrader: 0 / 0%
Quote:
Originally Posted by J. H. Rasmussen View Post
Here is an example you might want to play with, it uses javascript/ajax:
Thanks a lot J.H., I will play with it this weekend and let you know of the results. Regards.
__________________
Free domain name generator
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply

Tags
ajax, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX / Javascript question... splap Coding Forum 2 10-15-2009 06:54 AM
Google and AJAX Libraries API. To use or not to use that is the question ? lordspace Web Design Lobby 3 12-18-2008 01:28 PM
Add AJAX? birdbrain24 Coding Forum 1 02-05-2008 09:03 AM
AJAX: bots hitting AJAX scripts kkiely Coding Forum 1 04-21-2007 01:14 AM
AJAX Question alegnafire SEO Forum 5 04-05-2006 10:13 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 03:33 PM.
Powered by vBulletin
Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.