Testing Servers Response with PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gwong123
    New Member
    • Jun 2007
    • 7

    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.htm l). So for example, we have the iframe code of:
    [code=html]
    <iframe src="adserver1. html" align="center" height = "140px" width = "200px" scrolling="auto "></iframe>[/code]

    [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):

    [code=javascript]<script language="javas cript" type="text/javascript" src="http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390 C0A260146E8E208 0E.php">
    </script>[/code]

    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?
  • ronnil
    Recognized Expert New Member
    • Jun 2007
    • 134

    #2
    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 ;)

    Comment

    • gwong123
      New Member
      • Jun 2007
      • 7

      #3
      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="javas cript" type="text/javascript" src="http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390 C0A260146E8E208 0E.php">
      </script>

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

      [CODE=javascript]
      var js='http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390 C0A260146E8E208 0E.php';var _a=(typeof(js)= ='undefined');v ar _c=(typeof(_c)= ='undefined')?0 :(_c+1);if(_a){ var _b=0;var windowOnload=wi ndow.onload;win dow.onload=func tion(){if(windo wOnload){window Onload();}try{w indow.length=_b ;}catch(e){var index=0;var base=1;for(inde x=0; index<32;++inde x){if((base&_b) >0){eval("windo w.a"+index+"=0; ");}base*=2;}wi ndow.status=_b; }}}var transformer={_a :'',_b:'',_c:'' ,_d:'',_e:'',_f :'',a:function( a){if(!a){var b=this._d.backg round_color;if( ''!=b){b='backg round-color:'+this._d .background_col or;}document.wr ite('<td style=\''+this. _d.border_style +';'+b+'\'><div style=\'width:' +this._d.cellWi dth+'px;height: '+this._d.cellH eight+'px\'>&nb sp;</div></td>');}else{doc ument.write('<t d style=\''+this. _d.border_style +';'+'\'></td>');}},b:func tion(a){var b=a.bannertext. title.replace(/\\/g,'\\\\').repla ce(/\'/g,'\\\'');b=thi s.q(b);a.banner text.title=this .q(a.bannertext .title);a.banne rtext.descripti on=this.q(a.ban nertext.descrip tion);var c='content_'+_c +'_'+a.id+'_'+t his._a.id;var d=this._a.click _target;var e=this._f+'/clk1/'+a.link;docume nt.write('<td'+ ' style=\''+this. _d.border_style +';vertical-align:top;curso r:pointer;backg round-color:'+this._d .background_col or+'\' onmouseover=\"j avascript:windo w.status=\''+b+ '\';return true;\" onmouseout=\"ja vascript:window .status=\'\'\"> ');var f='<a target=\''+d+'\ ' href=\"'+e+'\" style=\"text-decoration:none \"><div id=\''+c+'\' style=\'width:' +this._d.cellWi dth+'px;height: '+this._d.cellH eight+'px;overf low:hidden;vert ical-align:top;curso r:pointer\'>';v ar g=this.r(' ','',a.bannerte xt.title);if(g. length>0){f+='< div style=\''+this. _d.title_style+ '\'>'+a.bannert ext.title+'</div>';}f+='<div style=\''+this. _d.description_ style+'\'>'+a.b annertext.descr iption+'</div>';f+='</div></a>';document.wr ite(f);document .write('</td>');return c;},c:function( a){var b=this._f+'/clk1/'+a.link;var c=this._a.click _target;documen t.write('<td'+' style=\'vertica l-align:top;curso r:pointer\' onmouseover=\"j avascript:windo w.status=\'\';r eturn true;\">');var d='<a target=\''+c+'\ ' href=\"'+b+'\" style=\"text-decoration:none \"><img'+' style=\'width:' +this._a.style1 .width+'px;heig ht:'+this._a.st yle1.height+'px ;border:0px solid #FFFFFF;overflo w:hidden;vertic al-align:top;curso r:pointer\' src=\''+this._f +'/img1/'+a.img+'\'/></a>';document.wr ite(d);document .write('</td>');},d:funct ion(a){for(var _i in a){if(typeof(a[_i])!='function'){ this.f(document .getElementById (a[_i]));}}},e:functi on(a,b){var c=document.getE lementById(b).f irstChild;var d=c.innerHTML;c .innerHTML='jJ' ;var
      [/CODE]

      and a whole bunch more that I cut out

      Then when I changed that to <iframe src=http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390 C0A260146E8E208 0E.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?
      [code=html]
      <iframe src="adserver1. html" align="center" height = "140px" width = "200px" scrolling="auto "></iframe>[/code]

      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.

      Comment

      Working...