从crons,SOAP,命令行任务和队列调用Zend Framework服务层(Calling Zend Framework Service Layer from crons, SOAP, comma

系统教程 行业动态 更新时间:2024-06-14 17:01:31
从crons,SOAP,命令行任务和队列调用Zend Framework服务层(Calling Zend Framework Service Layer from crons, SOAP, command line tasks and Queues)

我正试图找到使用Zend Framework为企业应用程序实现Model的最佳方式。 从不同的文章我现在确信服务层是一个非常好的主意。 我发现赞成服务层的一个观点是 - 它可以从外部调用 - 比如crons,SOAP,命令行任务和队列。

但我不清楚它是如何做到的。 当从外部调用服务时,Bootstrap将不会运行,因此该模型将没有关于数据库,邮件传输,日志记录等的信息。

有什么建议么?

I am trying to find the best way to implement Model using Zend Framework for an enterprise application. From different articles I am now convinced that a Service Layer is a very good idea. I see that one of the arguments in favor of Service Layer is that - it can be called from outside - like from crons, SOAP, command line tasks and Queues.

But I am not clear how it can do so. When services are called from outside the Bootstrap will not run hence the model will have no information about the DB, Mail Transport, Logging etc.

Any suggestions?

最满意答案

我们使用了一个简单的init.inc.php脚本,该脚本包含在我们的命令行脚本和cronjob脚本中,它们引导我们需要的资源:

<?php // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application') ); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); // we can't afford not have a APPLICATION_ENV, so return a fatal error in this case defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : '')); chdir(APPLICATION_PATH); /** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $resources = array('autoload', 'config', 'multidb', 'logger', 'cache', 'settings'); foreach ($resources as $resource) { $application->bootstrap($resource); } set_time_limit(1200); ini_set('memory_limit', '700M'); $resources数组是您希望加载的引导函数 APPLICATION_ENV通常是由.htaccess设置的变量,因此您必须将其设置为shell变量(或者将其包含在init.inc.php )

We're using a simple init.inc.php script that we include in our command line scripts and cronjob scripts, which bootstrap the resources that we need:

<?php // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application') ); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); // we can't afford not have a APPLICATION_ENV, so return a fatal error in this case defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : '')); chdir(APPLICATION_PATH); /** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $resources = array('autoload', 'config', 'multidb', 'logger', 'cache', 'settings'); foreach ($resources as $resource) { $application->bootstrap($resource); } set_time_limit(1200); ini_set('memory_limit', '700M'); the $resources array is the bootstrap functions you wish to load the APPLICATION_ENV is usually a variable set by .htaccess, so you'll have to set it a shell variable (or just include it in the init.inc.php)

更多推荐

本文发布于:2023-04-20 16:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/ac9aab5a93eb600af8a443cfaa1a6c9f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   命令行   Zend   Framework   SOAP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!