Zend framework Zend框架Zend_队列实现
我是ZEND的新手,正在开发版本(ZEND 1.11.1)。我试图在我的ZEND应用程序中实现ZEND_队列,但没有适合我的教程。我一直在尝试实现队列 我正在为DB开发一个队列。应用程序的工作流程如下所示: 1.用户通过应用程序输入SQL查询并等待结果。 2.一旦查询成功完成,查询将移动到队列并使用数据库进行处理。查询应将结果发送给用户 在我的控制器内:Zend framework Zend框架Zend_队列实现,zend-framework,zend-db,zend-db-table,job-queue,Zend Framework,Zend Db,Zend Db Table,Job Queue,我是ZEND的新手,正在开发版本(ZEND 1.11.1)。我试图在我的ZEND应用程序中实现ZEND_队列,但没有适合我的教程。我一直在尝试实现队列 我正在为DB开发一个队列。应用程序的工作流程如下所示: 1.用户通过应用程序输入SQL查询并等待结果。 2.一旦查询成功完成,查询将移动到队列并使用数据库进行处理。查询应将结果发送给用户 在我的控制器内: class IndexController extends Zend_Controller_Action { public functio
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$options = array(
'name' => 'queue1',
'driverOptions' => array(
'host' => '127.0.0.1',
'port' => '3306',
'username' => 'queue',
'password' => 'queue',
'dbname' => 'queue',
'type' => 'pdo_mysql'
)
);
// Create a database queue.
// Zend_Queue will prepend Zend_Queue_Adapter_ to 'Db' for the class name.
$queue = new Zend_Queue('Db', $options);
foreach ($queue->getQueues() as $name) {
echo $name, "\n";
}
$queue->send('My Test Message');
}
}
// file: application/controllers/IndexController.php
require_once "EmailPopo.php";
public function indexAction()
{
$queueAdapter = Zend_Registry::getInstance()->queueAdapter;
$options = array( 'name' => 'emailqueue' );
$queue = new Zend_Queue( $queueAdapter, $options );
$email = new EmailPopo();
$email->date = time();
$email->from = "minnie.mouse@disney.com";
$email->to = "mickey.mouse@disney.com";
$email->subject = "I want a divorce";
$email->body = "Letter's in the mail.";
$message = base64_encode( gzcompress( serialize( $email ) ) );
$queue->send( $message );
}
public function queueAction() {
$queueAdapter = Zend_Registry::getInstance()->queueAdapter;
$options = array( 'name' => 'emailqueue' );
$queue = new Zend_Queue( $queueAdapter, $options );
$messages = $queue->receive( 2 );
foreach( $messages as $message ) {
try {
$email = unserialize( gzuncompress( base64_decode( $message->body ) ) );
$queue->deleteMessage( $message );
echo sprintf(
"Sent email to %s (time: %s)<br/>",
$email->to,
new Zend_Date( $email->date )
);
} catch( Exception $ex ) {
echo "Kaboom!: " . $ex->getMessage() . "<br/>";
}
}
die( "Done" );
}
我面临的问题是,我无法理解要在哪个文件夹中添加代码
我没有在我的应用程序中使用模型,因为应用程序的要求是只使用控制器和视图
此外,当我尝试扩展Zend_队列_适配器_Db时,我收到以下错误:
致命错误:找不到类“ZendJobQueue”
或
致命错误:F:\wamp\www\helloworld\library\Zend\Controller\Dispatcher\Standard.php:242堆栈跟踪:#0 F:\wamp\www\helloworld\library\Zend\Controller\Front.php(946):
请为我提供正确的文件夹或任何教程,以帮助初学者使用ZEND JOBQUEUE。我在以下链接中获得了一些有用的代码: 我所做的与网站指示的完全相同:
; file: application/configs/application.ini
[production]
; ...
resources.frontController.params.displayExceptions = 0
; ...
queue.driverOptions.type = "pdo_mysql"
queue.driverOptions.host = "localhost"
queue.driverOptions.username = "howtoqueue"
queue.driverOptions.password = "howtoqueue"
queue.driverOptions.dbname = "howtoqueue"
在Boostrap.php文件中添加了以下代码:
<?php
// file: application/Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initQueue()
{
$options = $this->getOptions();
$queueAdapter = new Zend_Queue_Adapter_Db( $options[ 'queue' ] );
Zend_Registry::getInstance()->queueAdapter = $queueAdapter;
}
}
独自一人,我很困惑,为什么它在不同的情况下给出不同的输出。几个小时后,如果我再次运行代码,它会给我第一个O/P
数据库更改:
我有两个用于此应用程序的表,它们是:
CREATE TABLE IF NOT EXISTS `message` (
`message_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`queue_id` int(10) unsigned NOT NULL,
`handle` char(32) DEFAULT NULL,
`body` varchar(8192) NOT NULL,
`md5` char(32) NOT NULL,
`timeout` decimal(14,4) unsigned DEFAULT NULL,
`created` int(10) unsigned NOT NULL,
PRIMARY KEY (`message_id`),
UNIQUE KEY `message_handle` (`handle`),
KEY `message_queueid` (`queue_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
ALTER TABLE `message`
ADD CONSTRAINT `message_ibfk_1` FOREIGN KEY (`queue_id`) REFERENCES `queue` (`queue_id`) ON DELETE CASCADE ON UPDATE CASCADE;
2.排队
CREATE TABLE IF NOT EXISTS `queue` (
`queue_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`queue_name` varchar(100) NOT NULL,
`timeout` smallint(5) unsigned NOT NULL DEFAULT '30',
PRIMARY KEY (`queue_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
以上两种是DB结构。
我可以看到队列表中插入了一些数据,但我不知道哪个会受到影响
请帮助我理解队列和脚本的结构
工作正常吗?如果我理解上面的逻辑,并希望能够在Zend中为查询执行创建一个DB队列。我正努力想得到一些解释
对我来说,复制和粘贴代码不是一个好的编程,知道我在做什么是好的
谢谢大家!!任何帮助都将不胜感激 我在下面的链接中得到了一些有用的代码: 我所做的与网站指示的完全相同:
; file: application/configs/application.ini
[production]
; ...
resources.frontController.params.displayExceptions = 0
; ...
queue.driverOptions.type = "pdo_mysql"
queue.driverOptions.host = "localhost"
queue.driverOptions.username = "howtoqueue"
queue.driverOptions.password = "howtoqueue"
queue.driverOptions.dbname = "howtoqueue"
在Boostrap.php文件中添加了以下代码:
<?php
// file: application/Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initQueue()
{
$options = $this->getOptions();
$queueAdapter = new Zend_Queue_Adapter_Db( $options[ 'queue' ] );
Zend_Registry::getInstance()->queueAdapter = $queueAdapter;
}
}
独自一人,我很困惑,为什么它在不同的情况下给出不同的输出。几个小时后,如果我再次运行代码,它会给我第一个O/P
数据库更改:
我有两个用于此应用程序的表,它们是:
CREATE TABLE IF NOT EXISTS `message` (
`message_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`queue_id` int(10) unsigned NOT NULL,
`handle` char(32) DEFAULT NULL,
`body` varchar(8192) NOT NULL,
`md5` char(32) NOT NULL,
`timeout` decimal(14,4) unsigned DEFAULT NULL,
`created` int(10) unsigned NOT NULL,
PRIMARY KEY (`message_id`),
UNIQUE KEY `message_handle` (`handle`),
KEY `message_queueid` (`queue_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
ALTER TABLE `message`
ADD CONSTRAINT `message_ibfk_1` FOREIGN KEY (`queue_id`) REFERENCES `queue` (`queue_id`) ON DELETE CASCADE ON UPDATE CASCADE;
2.排队
CREATE TABLE IF NOT EXISTS `queue` (
`queue_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`queue_name` varchar(100) NOT NULL,
`timeout` smallint(5) unsigned NOT NULL DEFAULT '30',
PRIMARY KEY (`queue_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
以上两种是DB结构。
我可以看到队列表中插入了一些数据,但我不知道哪个会受到影响
请帮助我理解队列和脚本的结构
工作正常吗?如果我理解上面的逻辑,并希望能够在Zend中为查询执行创建一个DB队列。我正努力想得到一些解释
对我来说,复制和粘贴代码不是一个好的编程,知道我在做什么是好的
谢谢大家!!任何帮助都将不胜感激