There is a way to easy running a web application in workerman to speed up without modiy to much files in app.
A package calling 'joanhey/adapterman'
After my trying, it not work normally.
Problems:
Key config for runing:
server {
listen 80;
server_name joomla5.cn;
root D:/git/php/joomla_workerman;
autoindex off;
#301_START
#301_END
#HTTP_TO_HTTPS_START
#HTTP_TO_HTTPS_END
#SSL_START
#SSL_END
location / {
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection "keep-alive";
proxy_set_header UPGRADE_INSECURE_REQUESTS 1;
proxy_http_version 1.1;
}
location ^~/administrator/ {
proxy_pass http://127.0.0.1:8081/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection "keep-alive";
proxy_set_header UPGRADE_INSECURE_REQUESTS 1;
proxy_http_version 1.1;
}
#REWRITE_START 引用url重写规则
#include vhosts/rewrite/blog3.local.conf;
#REWRITE_END
#PHP_START
#PHP_END
#PHPMYADMIN_START
#PHPMYADMIN_END
#DENY_FILES_START
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 403;
}
#DENY_FILES_END
location ~ .+\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 1d;
error_log nul;
access_log off;
}
location ~ .+\.(js|css|svg|woff2)$
{
expires 1h;
error_log nul;
access_log off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
access_log logs/joomla5.cn.access.log;
error_log logs/joomla5.cn.error.log;
}
i want a proper right start script. Which in run
function it will reset app initilizition, and other cached variables in memory or in classes propty.
Labels |
Added:
No Code Attached Yet
|
auto_globals_jit = Off
disable_functions=header,header_remove,headers_sent,http_response_code,setcookie,session_create_id,session_id,session_name,session_save_path,session_status,session_start,session_write_close,session_regenerate_id,set_time_limit
<?php
error_reporting(E_ALL&!E_DEPRECATED);
require_once __DIR__.'/libraries/vendor/autoload.php';
use Adapterman\Adapterman;
use Workerman\Worker;
function trace($msg, $nl = PHP_EOL){
fwrite(STDOUT, var_export($msg, true) . ($nl ? "\n" : null));
}
function flog($msg, $path = './log_admin.log'){
$msg = is_string($msg)? $msg: var_export($msg, true);
file_put_contents($path, $msg.PHP_EOL, FILE_APPEND);
}
Adapterman::init();
$http_worker = new Worker('http://0.0.0.0:8081'); // or 127.0.0.1:8080, or localhost:9000
$http_worker->count = 8; // or any positive integer
$http_worker->name = 'joomla admin'; // or any string
$http_worker->onWorkerStart = static function () {
require __DIR__.'/start_admin.php';
};
$http_worker->onMessage = static function ($connection, $request) {
$request_uri = $request['server']['REQUEST_URI'];
flog($request_uri);
// flog($request_uri);
// if(str_contains($request_uri, 'media')){
// $file = '.'.$request_uri;
// $file = strstr($file, '?', true);
// $file = realpath($file);
// if(is_file($file)){
// $response = new \Workerman\Protocols\Http\Response();
//// $response->header('Content-Type', 'text/css');
// $response->withBody(file_get_contents($file));
//// header('Content-Type', mime_content_type($file));
// return $connection->send($response);
// }
// }
$connection->send(run_admin());
};
Worker::runAll();
<?php
use Joomla\CMS\WebAsset\WebAssetManager;
define('_JEXEC', 1);
function datetime(){
return date('Y-m-d H:i:s', time());
}
// Define JPATH constants if not defined yet
\defined('JPATH_BASE') || \define('JPATH_BASE', __DIR__);
\defined('JPATH_ROOT') || \define('JPATH_ROOT', JPATH_BASE);
\defined('JPATH_SITE') || \define('JPATH_SITE', JPATH_ROOT);
\defined('JPATH_PUBLIC') || \define('JPATH_PUBLIC', JPATH_ROOT);
\defined('JPATH_CONFIGURATION') || \define('JPATH_CONFIGURATION', JPATH_ROOT);
\defined('JPATH_ADMINISTRATOR') || \define('JPATH_ADMINISTRATOR', JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator');
\defined('JPATH_LIBRARIES') || \define('JPATH_LIBRARIES', JPATH_ROOT . DIRECTORY_SEPARATOR . 'libraries');
\defined('JPATH_PLUGINS') || \define('JPATH_PLUGINS', JPATH_ROOT . DIRECTORY_SEPARATOR . 'plugins');
\defined('JPATH_INSTALLATION') || \define('JPATH_INSTALLATION', JPATH_ROOT . DIRECTORY_SEPARATOR . 'installation');
\defined('JPATH_THEMES') || \define('JPATH_THEMES', JPATH_BASE . DIRECTORY_SEPARATOR .'administrator'.DIRECTORY_SEPARATOR. 'templates');
\defined('JPATH_CACHE') || \define('JPATH_CACHE', JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'cache');
\defined('JPATH_MANIFESTS') || \define('JPATH_MANIFESTS', JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'manifests');
\defined('JPATH_API') || \define('JPATH_API', JPATH_ROOT . DIRECTORY_SEPARATOR . 'api');
\defined('JPATH_CLI') || \define('JPATH_CLI', JPATH_ROOT . DIRECTORY_SEPARATOR . 'cli');
require_once JPATH_ADMINISTRATOR . '/includes/framework.php';
function run_admin(){
ob_start();
// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();
$container->alias('session.web', 'session.web.administrator')
->alias('session', 'session.web.administrator')
->alias('JSession', 'session.web.administrator')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.administrator')
->alias(\Joomla\Session\Session::class, 'session.web.administrator')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.administrator');
trace($_SERVER);
// $_SERVER['SERVER_NAME'] = 'joomla.cn';
// $_SERVER['HTTP_HOST'] = 'joomla.cn';
// if($_SERVER['REQUEST_URI'] == 'index.php'){
// $_SERVER['REQUEST_URI'] = '/';
// }else{
// $_SERVER['REQUEST_URI'] = str_ireplace('administrator/index.php', '', $_SERVER['REQUEST_URI']);
// }
// flog(datetime());
/*
* Alias the session service keys to the web session service as that is the primary session backend for this application
*
* In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
* is supported. This includes aliases for aliased class names, and the keys for aliased class names should be considered
* deprecated to be removed when the class name alias is removed as well.
*/
// Instantiate the application.
// Instantiate the application.
$app = $container->get(\Joomla\CMS\Application\AdministratorApplication::class);
// Set the application as global app
\Joomla\CMS\Factory::$application = $app;
// Set the application as global app
// Saves the start time and memory usage.
// Execute the application.
$app->execute();
$ret = $app->getBody();
\Joomla\CMS\Factory::$container = null;
\Joomla\CMS\Factory::$application = null;
// 重新设置webAssetManager 来恢复 locked 为false;
$webAssetManager = new WebAssetManager(\Joomla\CMS\Factory::getContainer()->get('webassetregistry'));
$app->getDocument()->setWebAssetManager($webAssetManager);
return $ret;
}
php -c C:/GreenSoft/EasySrv/core/software/php/php-8.2/php_disable.ini server_admin.php start
Labels |
Added:
Feature
|
Joomla is not a strictly separated front/backend application I have my doubts that you will get this running.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-02-15 09:03:35 |
Closed_By | ⇒ | Hackwar |
I've been thinking about this issue for several days and would really like to help you, but it already starts with the problem that I can't really find anything usefull about adaptman. And as Robert wrote, Joomla is not made for this, so I, too, fear that this wont be possible. Since I don't think we can provide support for this, I'm going to close this ticket. This isn't really a bug in Joomla, so not fitting for our bug tracker. But maybe you can get help in the Joomla forum at forum.joomla.org?
start.php
server.php
run.bat