Beanstalkd内存队列使用

阅读更多
pheanstalk_worker.php
getConnection()->isServiceListening();
	if(!$islive){
		_log('connection failed');
	}

	
	$job = $pheanstalk->watch('testtube')->ignore('default')->reserve();
	$job_encoded = json_decode($job->getData(),true);
	$done_jobs[] = $job_encoded;
	_log('job:'.$job->getData());
	$pheanstalk->delete($job);
	$cnt++ ;

	$memory = memory_get_usage();
    _log('memory:' . $memory.',cnt:' . $cnt);

    if($memory > 1000000) {
		//_log('exiting run due to memory limit');
		//exit;
    }

    usleep(10);
}


function _log($txt) {
	file_put_contents('log/worker.txt', $txt . "\n", FILE_APPEND);
}

 

";
print_R($pheanstalk->stats());
echo "
"; // ---------------------------------------- // producer (queues jobs) for($i=0;$i<10000;$i++){ $job = new stdClass(); $job->envelope_id = rand(); $job->date = date('Y-m-d H:i:s'); $job_data = json_encode($job); $pheanstalk->useTube('testtube')->put($job_data); echo "pushed: " . $job_data . "\n"; } // ---------------------------------------- // check server availability $pheanstalk->getConnection()->isServiceListening(); // true or false

 

你可能感兴趣的:(Beanstalkd,内存队列)