467,894 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Testing Servers Response with PHP

Hi all. Not sure if this is the right place to ask this but I'm not sure which language would be best to find a good solution.

Let me give you a quick overview before getting to the problem. Currently we have 8 ad servers. We are trying to make a site which will connect to each server and return back an ad banner, so loading the page will connect with all 8 servers and return 1 ad banner from each server.

Initially, javascript was used to connect to the servers using the server IP and location of the banner. But I was told to try to change it into iframes which I did. I'm no expert, but I was told a method which did work. This method had me create 8 new notepad txt files and each txt file contained one line of javascript code pertaining to a certain server. So 8 servers, 8 javascript lines in 8 txt files. For the sake of clarity, we'll call them adserver1.html, adserver2.html all the way to adserver8.html.

Then we have a site called servertest.html. The purpose of servertest.html is to test how quickly each of the 8 servers respond and the appropriate delay should be reflected on the site. So if one server responds fast, the ad banner pops up immediately and if another ad server responds 2 seconds slower, the ad will op up after 2 seconds of delay. (That was just an example, in reality, the delay is however long it takes for the server to respond).

The 8 iframe code lines are in this site (servertest.html). So for example, we have the iframe code of:
Expand|Select|Wrap|Line Numbers
  1. <iframe src="adserver1.html" align="center" height = "140px" width = "200px" scrolling="auto"></iframe>
[Please use CODE tags when posting source code. Thanks! --pbmods]

The adserver1.html file has the following line (the X's is the server IP address):

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript" src="http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390C0A260146E8E2080E.php">
  2. </script>
Now the problem we have is that it's messy. We want to try to find a way to compress the 8 adserver#.html txt files into either just one adserver.html file OR somehow have the iframes work in the servertest.html which doesn't require separate adserver#.html files.

OR, if it's easier, perhaps get rid of iframes completely and use some other method either using PHP or other languages.

Keep in mind the main goal of this is to test how quickly each server responds and displays their ad banner.

Is there a way, using PHP, to achieve this in a single document rather than having a total of 9 separate documents?
Jun 20 '07 #1
  • viewed: 1193
Share:
2 Replies
ronnil
Expert 100+
there certainly is.

the simplest thing would be to put the server urls in a database and load them from there

BUT since it's ONLY 8 lines this might be overkill

what i would do:

make a txt file called banners.txt or something

put 1 url per line

check out http://www.php.net/manual/en/ref.filesystem.php (hint: file() is the function you're looking for)

now when you got the contents of the file loaded into an array, you simply iterate through it.

you can keep the javascript almost intact if you like (for instance if you want to trigger the loading of the banners manually), but you can also write the entire code dynamically based on the contents of the file.

now, if you decide to add a ninth banner, all you need to do is add a single line in your banner.txt

-------------------
you can also keep the urls in another php-file in an array, include that php file and again iterate through that array

the possibilitys are endless, and you're not even gonna have to use php, you can use almost any kind of server-side language --- so I'm just gonna stop now ;)
Jun 20 '07 #2
I will have to try that soon. But will using an array and calling the data from that txt in the main document really work? Because before, the following javascript (the same line that is now in separate txt files) used to be located in the main document. It worked, but the page didn't load until each of the servers had responded/timed out. What we needed was for the servers to show their banners as soon as they were able to respond.

<script language="javascript" type="text/javascript" src="http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390C0A260146E8E2080E.php">
</script>

The above worked, but was slow and didn't achieve what we needed. When placed into a browser window, it returned:

Expand|Select|Wrap|Line Numbers
  1. var js='http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390C0A260146E8E2080E.php';var _a=(typeof(js)=='undefined');var _c=(typeof(_c)=='undefined')?0:(_c+1);if(_a){var _b=0;var windowOnload=window.onload;window.onload=function(){if(windowOnload){windowOnload();}try{window.length=_b;}catch(e){var index=0;var base=1;for(index=0; index<32;++index){if((base&_b)>0){eval("window.a"+index+"=0;");}base*=2;}window.status=_b;}}}var transformer={_a:'',_b:'',_c:'',_d:'',_e:'',_f:'',a:function(a){if(!a){var b=this._d.background_color;if(''!=b){b='background-color:'+this._d.background_color;}document.write('<td style=\''+this._d.border_style+';'+b+'\'><div style=\'width:'+this._d.cellWidth+'px;height:'+this._d.cellHeight+'px\'>&nbsp;</div></td>');}else{document.write('<td style=\''+this._d.border_style+';'+'\'></td>');}},b:function(a){var b=a.bannertext.title.replace(/\\/g,'\\\\').replace(/\'/g,'\\\'');b=this.q(b);a.bannertext.title=this.q(a.bannertext.title);a.bannertext.description=this.q(a.bannertext.description);var c='content_'+_c+'_'+a.id+'_'+this._a.id;var d=this._a.click_target;var e=this._f+'/clk1/'+a.link;document.write('<td'+' style=\''+this._d.border_style+';vertical-align:top;cursor:pointer;background-color:'+this._d.background_color+'\' onmouseover=\"javascript:window.status=\''+b+'\';return true;\" onmouseout=\"javascript:window.status=\'\'\">');var f='<a target=\''+d+'\' href=\"'+e+'\" style=\"text-decoration:none\"><div id=\''+c+'\' style=\'width:'+this._d.cellWidth+'px;height:'+this._d.cellHeight+'px;overflow:hidden;vertical-align:top;cursor:pointer\'>';var g=this.r(' ','',a.bannertext.title);if(g.length>0){f+='<div style=\''+this._d.title_style+'\'>'+a.bannertext.title+'</div>';}f+='<div style=\''+this._d.description_style+'\'>'+a.bannertext.description+'</div>';f+='</div></a>';document.write(f);document.write('</td>');return c;},c:function(a){var b=this._f+'/clk1/'+a.link;var c=this._a.click_target;document.write('<td'+' style=\'vertical-align:top;cursor:pointer\' onmouseover=\"javascript:window.status=\'\';return true;\">');var d='<a target=\''+c+'\' href=\"'+b+'\" style=\"text-decoration:none\"><img'+' style=\'width:'+this._a.style1.width+'px;height:'+this._a.style1.height+'px;border:0px solid #FFFFFF;overflow:hidden;vertical-align:top;cursor:pointer\' src=\''+this._f+'/img1/'+a.img+'\'/></a>';document.write(d);document.write('</td>');},d:function(a){for(var _i in a){if(typeof(a[_i])!='function'){this.f(document.getElementById(a[_i]));}}},e:function(a,b){var c=document.getElementById(b).firstChild;var d=c.innerHTML;c.innerHTML='jJ';var 
  2.  
and a whole bunch more that I cut out

Then when I changed that to <iframe src=http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390C0A260146E8E2080E.php"> it only returned the server information instead of the banner ad itself. It was only when I separated out the javascript lines into 8 separate documents and used the <iframe> tags to embed the external documents (adserver1.html etc) into the main site did it work.

It seems because the .php file contained javascript it can't be used with iframes on the same site I think?
Expand|Select|Wrap|Line Numbers
  1. <iframe src="adserver1.html" align="center" height = "140px" width = "200px" scrolling="auto"></iframe>
So I used the above iframe line to embed the javascript and was able to achieve what we needed. If I made it into an array, wouldn't that be the same as putting the javascript back into the main document and losing the iframes? Because I would have a txt file with 8 lines of javascript code for each server, put all that into an array, then iterate through it in the main document thus bringing about the old effect again.

I don't mind losing the iframes, as long as the desired effect is maintained but I'm worried that the array will put the javascript back in and return me back to the way things were when what I really need is to reduce the number of extra server files from 8 to 1 or none at all.

I apologize if my concern is rather noobish, but I'm just trying to make sure that things will return the right results.
Jun 20 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by gg.2.starfire | last post: by
reply views Thread by Brian Russell | last post: by
2 posts views Thread by balakrishnan.dinesh | last post: by
6 posts views Thread by Andy | last post: by
4 posts views Thread by David | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.