_src = $src; $startAt = strtotime( $start ); $stopAt = strtotime( $stop ); echo "start $start " . $startAt . "\n"; echo "stop $stop " . $stopAt . "\n"; $this->_queue[] = array( 'start' => $startAt, 'stop' => $stopAt, 'src' => $src ); // $this->dowload(); return true; } public function runQueue() { while( true ) { if( empty( $this->_queue ) ) { break; } $now = time(); for( $i = 0; $i < count( $this->_queue ); ++$i ) { $q = $this->_queue[$i]; if( $q['start'] > $now ) { continue; } echo "action\n"; print_r( $q ); $this->_src = $q['src']; $this->_startAt = $q['start']; $this->_stopAt = $q['stop']; unset( $this->_queue[$i] ); $this->_queue = array_values( $this->_queue ); } sleep( 1 ); } } protected function dowload() { $this->_srcFh = fopen( $this->_src, 'r' ); $this->_desFh = fopen( $this->_des, 'w' ); echo $this->_srcFh . "\n"; $stopAt = time() + ( 10 * 2 ); while( !feof( $this->_srcFh ) ) { $buffer = fgets( $this->_srcFh, 8096 ); $now = time(); echo "strlen $stopAt $now " . strlen( $buffer ) . "\n"; fwrite( $this->_desFh, $buffer ); if( $now > $stopAt ) { echo "stop\n"; break; } usleep( 300 ); } fclose( $this->_srcFh ); fclose( $this->_desFh ); } } date_default_timezone_set( 'Europe/Berlin' ); $f = new Fetch(); $now = time(); $start = date( 'Y-m-d H:i:s', $now + 5 ); $stop = date( 'Y-m-d H:i:s', $now + 30 ); $f->queue( $url, $start, $stop ); $start = date( 'Y-m-d H:i:s', $now + 7 ); $stop = date( 'Y-m-d H:i:s', $now + 30 ); $f->queue( 'http://www.lena.sub.org', $start, $stop ); $f->runQueue(); ?>