我有两个基于zend 2框架的应用程序,它们部署在同一台服务器上。 app1会将http请求调用到app2。 为了提高性能,我想绕过http层并从代码创建一个zend 2(app2)实例,然后覆盖它的请求并获得对变量的输出响应。
以下是我的尝试:
public function callAPIDirect($url, $params, $method = 'GET')
{
$app1_dir = getcwd();
chdir(APP2_PATH);
require APP2_PATH . '/init_autoloader.php';
$app2Configuration = require APP2_PATH . '/config/application.config.php';
$app2SmConfig = isset($app2Configuration['service_manager']) ? $app2Configuration['service_manager'] : array();
$app2ServiceManager = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig($app2SmConfig));
$app2ServiceManager->setService('ApplicationConfig', $app2Configuration);
$app2ServiceManager->get('ModuleManager')->loadModules();
$app2ListenerFromAppConfig = isset($app2Configuration['listeners']) ? $app2Configuration['listeners'] : array();
$app2Config = $app2ServiceManager->get('Config');
$app2ListenerFromConfigService = isset($app2Config['listeners']) ? $app2Config['listeners'] : array();
$app2Listeners = array_unique(array_merge($app2ListenerFromAppConfig, $conveyListenerFromConfigService));
$app2 = $app2serviceManager->get('Application')->bootstrap($app2Listeners);
$request = $app2->getRequest();
$uri = new \Zend\Uri\Http($url);
$queryString = $uri->getQuery();
$request->setMethod($method);
$request->setUri($uri);
$request->setRequestUri($uri->getPath());
$result = $app2->run();
chdir($app1_dir);
return $result;
}
但似乎Zend框架的类已经加载到app1中,无法在app2中加载。此外,app2无法正确实例化。
由于