PHP Classes

File: time_server.php

Recommend this page to a friend!
  Classes of MC Breit   Simple Server   time_server.php   Download  
File: time_server.php
Role: Example script
Content type: text/plain
Description: A simple timeserver, prints out the local server time in ISO 8601 - Demonstrates the "connection close" routine..
Class: Simple Server
Implement TCP socket servers
Author: By
Last change:
Date: 18 years ago
Size: 2,459 bytes
 

Contents

Class file image Download
<?php
/***************************************************************************
 * SimpleServer Example 2
 * ----------------------
 * begin : Saturday, Dec 4, 2004 - 23:30
 * copyright : (C) 2004 MC Breit
 * email : support@mcb.cc - MCB.CC - Free and Open Sources
 * last modified : 04/12/04 - 23:44 - MC Breit
 * version : 1.0.0
 *
 ***************************************************************************/

/***************************************************************************
 *
 * 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 example will show how easy to create your own Time Server.
 *
 * What should our Time Server do?
 * He should ait for connect ins, then give the accutal time to
 * the client and close the connection, waiting for the next one..
 * The timeformat should be the European Timefmt on ISO 8601
 * (eg. 2004-12-05T01:30:33+01:00)
 *
 *
 * !! Important: Dont forget your firewall settings while testing !!
 ***************************************************************************/

//Kill the max_ex_time (on pure installations not needed)
set_time_limit(0);

//Get the timezone of this computer..
$timezone = date('O');
$timezone = substr($timezone, 0, 3).':'.substr($timezone, -2);
 
//Including the main class..
include('SimpleServer.class.php');

//Creating a new server object using port 9000 and the local ip "127.0.0.1".
$srv = &new SimpleServer(9000, '127.0.0.1');

//Main loop to listen for clients..
while( $srv->listen() )
{
 
//Print the time..
 
$srv->put(strftime('%Y-%m-%dT%H:%M:%S').$timezone);
 
 
//Close connection to client and wait for the next one..
 
$srv->close();
 
 
//Any errors inside this loop?
 
if( $error = $srv->get_error_str() )
  {
    print
$error;
  }
}

//Any errors while shutting down?
if( $error = $srv->get_error_str() )
{
  print
$error;
}

//
// Thats it folks!
//
?>