Location: PHPKode > scripts > sLog > sLog-0.8/http/slogtest.php
<?php
/** sLog v0.8
 *  copyright (c) 2008 Kjell-Inge Gustafsson kigkonsult
 *  www.kigkonsult.se/slog/index.php
 *  hide@address.com
 *
 *  Description:
 *  This file is a PHP HTTP sLog database test interface
 *
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the  Free
 *  Software Foundation; either version 2 of the License, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 *  more details.
 *
 *  You should have received a copy of the GNU General Public License along with
 *  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 *  Place, Suite 330, Boston, MA  02111-1307  USA
 */
require_once '../include/form.php';
fixInput($_REQUEST, 'insertLog.php' );
// $o = null; foreach($_REQUEST as $k=>$v) $o.="$k : $v<br />\n";echo $o;// test ###
$formParams = array();
if( isset( $_REQUEST['submit'] ) && ( 0 < $_REQUEST['count'] )) {
  $formParams['message'] = null;
            /* using PEAR HTTP_Request */
  require_once 'HTTP/Request.php';
            /* EXECUTE TEST */
  $time_start   = getmicrotime();
  $delay        = 1000; // microseconds between calls
  for($cnt = 0; $cnt < $_REQUEST['count']; $cnt++ ) {
    $req        = & new HTTP_Request( $_REQUEST['WSurl'] );
    $req->setMethod( HTTP_REQUEST_METHOD_POST );
    $parameters = fixLogparams( $cnt, $_REQUEST );
    $parameters['subject'] .= ' http';
    foreach( $parameters as $name => $value )
      $req->addPostData( $name, $value );
    if ( !PEAR::isError( $req->sendRequest())) {
      $response = $req->getResponseBody();
      if( $response != '0' ) {
        $formParams['message'] = "return: $response";
        $_REQUEST['count'] = $cnt + 1;
        break;
      }
    }
    else {
      $formParams['message'] = 'return: HTTP '.$req->getResponseCode();
      $_REQUEST['count'] = $cnt + 1;
      break;
    }
    usleep( $delay ); // delay between calls
  }
  $time_end                 = getmicrotime();
  $formParams['delay']      = ($_REQUEST['count'] * $delay) / 1000000; // total delay in seconds
  $time                     = $time_end - $time_start - $formParams['delay'];
  $formParams['time']       = number_format( $time, 4 );
  if( empty( $formParams['message'] ) && 1 < $_REQUEST['count'] ) {
    $formParams['avgTime']  = ', avg='.number_format(( $time / $_REQUEST['count'] ), 4 );
    $formParams['avgTime'] .= '<br />(excluding total wait time between calls='.number_format( $formParams['delay'], 4 ).')';
  }
  else
    $formParams['avgTime']  = '';
}
$formParams['action']       = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$formParams['title']        = 'sLog simple http test';
$formParams['header']       = 'sLog http access test';
$formParams['text']         = 'Test the capacity of sLog, fill in the number of test log events, update log item counts and START TEST.';
$formParams['URLlegend']    = 'InsertLog URL';
$formParams['URLlabel']     = 'URL';
form( $_REQUEST, $formParams );
?>
Return current item: sLog