日期:2014-05-16 浏览次数:20496 次
<?php
require_once(realpath(dirname(__FILE__)).'/../pheanstalk/pheanstalk_init.php');
class AppRemoteLib {
var $beanhost = false;
var $beanport = false;
var $beanhandle = false;
function openqueue($host, $port) {
if ($this->beanhost || $this->beanport) return false;
$this->beanhost = $host;
$this->beanport = $port;
$this->beanhandle = new Pheanstalk($host, $port);
if (!$this->beanhandle) return false;
return true;
}
public function putrequest()
{
try {
$this->beanhandle->useTube('test');
$jobid = $this->beanhandle->put('some data', 1000, 0,1 );
} catch (Exception $e) {
$jobid = false;
}
return $jobid;
}
public function fetch($tube, $timeout=0) {
try {
$this->beanhandle->watch($tube);
$job = $this->beanhandle->reserve($timeout);
} catch (Exception $e) {
return false;
}
if (!$job) return false;
var_dump($job);
sleep(10);
try {
$this->beanhandle->delete($job);
} catch (Exception $e) {
return false;
}
return $job;
}
private function watch($tube) {
$this->beanhandle->watch($tube);
}
private function fetchall($timeout=0) {
try {
$job = $this->beanhandle->reserve($timeout);
if (!$job) return false;
$this->beanhandle->delete($job);
} catch (Exception $e) {
}
return $job;
}
}
$appremotelib = new AppRemoteLib();
$appremotelib->openqueue("192.168.19.128", "11911");
$appremotelib->putrequest();
$job = $appremotelib->fetch('test', 2);
?>