php使用beanstalkd 過程分享
一、安裝
1、安裝libevent
引用
wget http://cloud.github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz
cp libevent-1.4.14b-stable.tar.gz /usr/local/src/
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure --prefix=/usr/local/libevent
make
make install
2、安裝beanstalkd(本文提供附件)
引用
cp beanstalkd-1.4.6.tar.gz /usr/local/src/
tar zxvf beanstalkd-1.4.6.tar.gz
cd beanstalkd-1.4.6
./configure --prefix=/usr/local/beanstalkd
make
make install
./beanstalkd -d -l 127.0.0.1 -p 11300
3、php用戶端的使用,建議採用源碼的方式,不用擴充的方式。
http://sourceforge.net/projects/beanstalk/ 下載php用戶端代碼
引用
require('./BeanStalk.class.php');
$beanstalk = BeanStalk::open(array(
'servers' => array( '127.0.0.1:11300' ),
'select' => 'random peek'
));
$beanstalk->use_tube('foo');
$beanstalk->put(0, 0, 120, 'say hello world');
$beanstalk->watch('foo');
$job = $beanstalk->reserve_with_timeout();
echo $job->get(); // Output: 'say hello world'
Beanstalk::delete($job); // Delete the job.
?>