00001 <?PHP
00002 
00003 class lockableClass
00004 {
00005         var $lockfile;              
00006         
00023         function lock()
00024         {
00025                 $maxtime = 600; 
00026                 $i = 0;
00027                 
00028                 while( file_exists( $this->lockfile ) )
00029                 {
00030                         usleep( 100 );
00031                         if( $i++ > $maxtime )
00032                         {
00033                                 
00034                                 if( filemtime( $this->lockfile ) < time() - ini_get( "max_execution_time" ) )
00035                                         break;
00036                                 else
00037                                         return false;
00038                         }
00039                 }
00040                 touch( $this->lockfile );
00041                 return true;
00042         }
00043         
00047         function unlock()
00048         {
00049                 unlink( $this->lockfile );
00050         }
00051 }
00052 ?>