Commit 2651c0ad by 杨树贤

添加laravel-s拓展到项目(swoole加速)

parent 86797b8c
#!/usr/bin/env bash
WORK_DIR=$1
if [ ! -n "${WORK_DIR}" ] ;then
WORK_DIR="."
fi
echo "Restarting LaravelS..."
./bin/laravels restart -d -i
echo "Starting fswatch..."
LOCKING=0
fswatch -e ".*" -i "\\.php$" -r ${WORK_DIR} | while read file
do
if [[ ! ${file} =~ .php$ ]] ;then
continue
fi
if [ ${LOCKING} -eq 1 ] ;then
echo "Reloading, skipped."
continue
fi
echo "File ${file} has been modified."
LOCKING=1
./bin/laravels reload
LOCKING=0
done
exit 0
\ No newline at end of file
#!/usr/bin/env bash
WORK_DIR=$1
if [ ! -n "${WORK_DIR}" ] ;then
WORK_DIR="."
fi
echo "Restarting LaravelS..."
./bin/laravels restart -d -i
echo "Starting inotifywait..."
LOCKING=0
inotifywait --event modify --event create --event move --event delete -mrq ${WORK_DIR} | while read file
do
if [[ ! ${file} =~ .php$ ]] ;then
continue
fi
if [ ${LOCKING} -eq 1 ] ;then
echo "Reloading, skipped."
continue
fi
echo "File ${file} has been modified."
LOCKING=1
./bin/laravels reload
LOCKING=0
done
exit 0
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
* 本autoloader只用来拉取laravelS
* Class Psr4Autoloader
*/
class Psr4Autoloader
{
/**
* An associative array where the key is a namespace prefix and the value
* is an array of base directories for classes in that namespace.
*
* @var array
*/
protected $prefixes = array();
/**
* Register loader with SPL autoloader stack.
*
* @return void
*/
public function register()
{
spl_autoload_register(array($this, 'loadClass'));
}
/**
* Adds a base directory for a namespace prefix.
*
* @param string $prefix The namespace prefix.
* @param string $base_dir A base directory for class files in the
* namespace.
* @param bool $prepend If true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last.
* @return void
*/
public function addNamespace($prefix, $base_dir, $prepend = false)
{
// normalize namespace prefix
$prefix = trim($prefix, '\\') . '\\';
// normalize the base directory with a trailing separator
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/';
// initialize the namespace prefix array
if (isset($this->prefixes[$prefix]) === false) {
$this->prefixes[$prefix] = array();
}
// retain the base directory for the namespace prefix
if ($prepend) {
array_unshift($this->prefixes[$prefix], $base_dir);
} else {
array_push($this->prefixes[$prefix], $base_dir);
}
}
/**
* Loads the class file for a given class name.
*
* @param string $class The fully-qualified class name.
* @return mixed The mapped file name on success, or boolean false on
* failure.
*/
public function loadClass($class)
{
// the current namespace prefix
$prefix = $class;
// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while (false !== $pos = strrpos($prefix, '\\')) {
// retain the trailing namespace separator in the prefix
$prefix = substr($class, 0, $pos + 1);
// the rest is the relative class name
$relative_class = substr($class, $pos + 1);
// try to load a mapped file for the prefix and relative class
$mapped_file = $this->loadMappedFile($prefix, $relative_class);
if ($mapped_file) {
return $mapped_file;
}
// remove the trailing namespace separator for the next iteration
// of strrpos()
$prefix = rtrim($prefix, '\\');
}
// never found a mapped file
return false;
}
/**
* Load the mapped file for a namespace prefix and relative class.
*
* @param string $prefix The namespace prefix.
* @param string $relative_class The relative class name.
* @return mixed Boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded.
*/
protected function loadMappedFile($prefix, $relative_class)
{
// are there any base directories for this namespace prefix?
if (isset($this->prefixes[$prefix]) === false) {
return false;
}
// look through base directories for this namespace prefix
foreach ($this->prefixes[$prefix] as $base_dir) {
// replace the namespace prefix with the base directory,
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $base_dir
. str_replace('\\', '/', $relative_class)
. '.php';
// if the mapped file exists, require it
if ($this->requireFile($file)) {
// yes, we're done
return $file;
}
}
// never found it
return false;
}
/**
* If a file exists, require it from the file system.
*
* @param string $file The file to require.
* @return bool True if the file exists, false if not.
*/
protected function requireFile($file)
{
if (file_exists($file)) {
require $file;
return true;
}
return false;
}
}
$basePath = realpath(__DIR__ . '/../');
$loader = new Psr4Autoloader();
$loader->register();
$loader->addNamespace('Hhxsv5\LaravelS', $basePath . '/vendor/hhxsv5/laravel-s/src');
$loader->addNamespace('Symfony\Component\Console', $basePath . '/vendor/symfony/console');
$loader->addNamespace('Symfony\Contracts\Service', $basePath . '/vendor/symfony/service-contracts');
$loader->addNamespace('Symfony\Contracts', $basePath . '/vendor/symfony/contracts');
$command = new Hhxsv5\LaravelS\Console\Portal($basePath);
$input = new Symfony\Component\Console\Input\ArgvInput();
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$code = $command->run($input, $output);
exit($code);
\ No newline at end of file
......@@ -27,6 +27,8 @@ $app = new Laravel\Lumen\Application(
// $app->withEloquent();
$app->register(Hhxsv5\LaravelS\Illuminate\LaravelSServiceProvider::class);
/*
|--------------------------------------------------------------------------
| Register Container Bindings
......
......@@ -7,7 +7,8 @@
"require": {
"php": ">=5.6.4",
"laravel/lumen-framework": "5.5.*",
"vlucas/phpdotenv": "~2.2"
"vlucas/phpdotenv": "~2.2",
"hhxsv5/laravel-s": "~3.5.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d7ca23bfe3adecc3beda85d197db4a0b",
"content-hash": "6217641796c92c3ef02247c4e3fd7a58",
"packages": [
{
"name": "doctrine/inflector",
......@@ -80,6 +80,85 @@
"time": "2018-01-09T20:05:19+00:00"
},
{
"name": "hhxsv5/laravel-s",
"version": "v3.5.9",
"source": {
"type": "git",
"url": "https://github.com/hhxsv5/laravel-s.git",
"reference": "334f80ac9db219d0ef7a4fffc3546ba804ff180a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hhxsv5/laravel-s/zipball/334f80ac9db219d0ef7a4fffc3546ba804ff180a",
"reference": "334f80ac9db219d0ef7a4fffc3546ba804ff180a",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"ext-json": "*",
"ext-pcntl": "*",
"php": ">=5.5.9",
"swoole/ide-helper": "@dev",
"symfony/console": ">=2.7.0"
},
"suggest": {
"ext-inotify": "Inotify, used to reload all worker processes when your code is modified.",
"ext-swoole": "Event-driven asynchronous & concurrent & coroutine networking engine with high performance for PHP, require >= 1.7.19."
},
"bin": [
"bin/fswatch"
],
"type": "library",
"extra": {
"laravel": {
"providers": [
"Hhxsv5\\LaravelS\\Illuminate\\LaravelSServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Hhxsv5\\LaravelS\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Xie Biao",
"email": "hhxsv5@sina.com"
}
],
"description": "🚀LaravelS is like a glue that is used to quickly integrate Swoole into Laravel or Lumen, and then give them better performance and more possibilities.",
"homepage": "https://github.com/hhxsv5/laravel-s",
"keywords": [
"async",
"coroutine",
"http",
"inotify",
"laravel",
"laravel-s",
"lumen",
"performance",
"process",
"server",
"swoole",
"task",
"tcp",
"timer",
"udp",
"websocket"
],
"time": "2019-07-29T03:59:41+00:00"
},
{
"name": "illuminate/auth",
"version": "v5.5.44",
"source": {
......@@ -1880,6 +1959,49 @@
"time": "2017-10-23T01:57:42+00:00"
},
{
"name": "swoole/ide-helper",
"version": "4.4.3",
"source": {
"type": "git",
"url": "https://github.com/swoole/ide-helper.git",
"reference": "d8fdeff72d0c01d8547c03272b0e6fb05f6c2aa6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swoole/ide-helper/zipball/d8fdeff72d0c01d8547c03272b0e6fb05f6c2aa6",
"reference": "d8fdeff72d0c01d8547c03272b0e6fb05f6c2aa6",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require-dev": {
"squizlabs/php_codesniffer": "~3.4.0",
"zendframework/zend-code": "~3.3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Swoole\\IDEHelper\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Team Swoole",
"email": "team@swoole.com"
}
],
"description": "IDE help files for Swoole.",
"time": "2019-08-09T06:19:25+00:00"
},
{
"name": "symfony/console",
"version": "v3.4.30",
"source": {
......
<?php
/**
* @see https://github.com/hhxsv5/laravel-s/blob/master/Settings-CN.md Chinese
* @see https://github.com/hhxsv5/laravel-s/blob/master/Settings.md English
*/
return [
'listen_ip' => env('LARAVELS_LISTEN_IP', '127.0.0.1'),
'listen_port' => env('LARAVELS_LISTEN_PORT', 5200),
'socket_type' => defined('SWOOLE_SOCK_TCP') ? SWOOLE_SOCK_TCP : 1,
'enable_coroutine_runtime' => false,
'server' => env('LARAVELS_SERVER', 'LaravelS'),
'handle_static' => env('LARAVELS_HANDLE_STATIC', false),
'laravel_base_path' => env('LARAVEL_BASE_PATH', base_path()),
'inotify_reload' => [
'enable' => env('LARAVELS_INOTIFY_RELOAD', false),
'watch_path' => base_path(),
'file_types' => ['.php'],
'excluded_dirs' => [],
'log' => true,
],
'event_handlers' => [],
'websocket' => [
'enable' => false,
//'handler' => XxxWebSocketHandler::class,
],
'sockets' => [],
'processes' => [
//[
// 'class' => \App\Processes\TestProcess::class,
// 'redirect' => false, // Whether redirect stdin/stdout, true or false
// 'pipe' => 0 // The type of pipeline, 0: no pipeline 1: SOCK_STREAM 2: SOCK_DGRAM
//],
],
'timer' => [
'enable' => false,
'jobs' => [
// Enable LaravelScheduleJob to run `php artisan schedule:run` every 1 minute, replace Linux Crontab
//\Hhxsv5\LaravelS\Illuminate\LaravelScheduleJob::class,
// Two ways to configure parameters:
// [\App\Jobs\XxxCronJob::class, [1000, true]], // Pass in parameters when registering
// \App\Jobs\XxxCronJob::class, // Override the corresponding method to return the configuration
],
'max_wait_time' => 5,
],
'events' => [],
'swoole_tables' => [],
'register_providers' => [],
'cleaners' => [
//Hhxsv5\LaravelS\Illuminate\Cleaners\SessionCleaner::class, // If you use the session or authentication in your project, please uncomment this line
//Hhxsv5\LaravelS\Illuminate\Cleaners\AuthCleaner::class, // If you use the authentication or passport in your project, please uncomment this line
//Hhxsv5\LaravelS\Illuminate\Cleaners\JWTCleaner::class, // If you use the package "tymon/jwt-auth" in your project, please uncomment this line
// ...
],
'destroy_controllers' => [
'enable' => false,
'excluded_list' => [
//\App\Http\Controllers\TestController::class,
],
],
'swoole' => [
'daemonize' => env('LARAVELS_DAEMONIZE', false),
'dispatch_mode' => 2,
'reactor_num' => function_exists('swoole_cpu_num') ? swoole_cpu_num() * 2 : 4,
'worker_num' => function_exists('swoole_cpu_num') ? swoole_cpu_num() * 2 : 8,
//'task_worker_num' => function_exists('swoole_cpu_num') ? swoole_cpu_num() * 2 : 8,
'task_ipc_mode' => 1,
'task_max_request' => 8000,
'task_tmpdir' => @is_writable('/dev/shm/') ? '/dev/shm' : '/tmp',
'max_request' => 8000,
'open_tcp_nodelay' => true,
'pid_file' => storage_path('laravels.pid'),
'log_file' => storage_path(sprintf('logs/swoole-%s.log', date('Y-m'))),
'log_level' => 4,
'document_root' => base_path('public'),
'buffer_output_size' => 2 * 1024 * 1024,
'socket_buffer_size' => 128 * 1024 * 1024,
'package_max_length' => 4 * 1024 * 1024,
'reload_async' => true,
'max_wait_time' => 60,
'enable_reuse_port' => true,
'enable_coroutine' => false,
'http_compression' => false,
// Slow log
// 'request_slowlog_timeout' => 2,
// 'request_slowlog_file' => storage_path(sprintf('logs/slow-%s.log', date('Y-m'))),
// 'trace_event_worker' => true,
/**
* More settings of Swoole
* @see https://wiki.swoole.com/wiki/page/274.html Chinese
* @see https://www.swoole.co.uk/docs/modules/swoole-server/configuration English
*/
],
];
{"server":{"listen_ip":"0.0.0.0","listen_port":"61009","socket_type":1,"enable_coroutine_runtime":false,"server":"LaravelS","handle_static":false,"laravel_base_path":"/home/vagrant/code/ic_server_welfare","inotify_reload":{"enable":false,"watch_path":"/home/vagrant/code/ic_server_welfare","file_types":[".php"],"excluded_dirs":[],"log":true},"event_handlers":[],"websocket":{"enable":false},"sockets":[],"processes":[],"timer":{"enable":false,"jobs":[],"max_wait_time":5},"events":[],"swoole_tables":[],"register_providers":[],"cleaners":[],"destroy_controllers":{"enable":false,"excluded_list":[]},"swoole":{"daemonize":true,"dispatch_mode":2,"reactor_num":2,"worker_num":2,"task_ipc_mode":1,"task_max_request":8000,"task_tmpdir":"/dev/shm","max_request":8000,"open_tcp_nodelay":true,"pid_file":"/home/vagrant/code/ic_server_welfare/storage/laravels.pid","log_file":"/home/vagrant/code/ic_server_welfare/storage/logs/swoole-2019-08.log","log_level":4,"document_root":"/home/vagrant/code/ic_server_welfare/public","buffer_output_size":2097152,"socket_buffer_size":134217728,"package_max_length":4194304,"reload_async":true,"max_wait_time":60,"enable_reuse_port":true,"enable_coroutine":false,"http_compression":false},"enable_gzip":false,"process_prefix":"/home/vagrant/code/ic_server_welfare","ignore_check_pid":false},"laravel":{"root_path":"/home/vagrant/code/ic_server_welfare","static_path":"/home/vagrant/code/ic_server_welfare/public","cleaners":[],"register_providers":[],"destroy_controllers":{"enable":false,"excluded_list":[]},"is_lumen":true,"_SERVER":{"LESSOPEN":"| /usr/bin/lesspipe %s","MAIL":"/var/mail/vagrant","USER":"vagrant","SSH_CLIENT":"10.0.2.2 57778 22","LANGUAGE":"en_US:","SHLVL":"1","HOME":"/home/vagrant","OLDPWD":"/home/vagrant","SSH_TTY":"/dev/pts/0","LOGNAME":"vagrant","_":"/usr/bin/php","XDG_SESSION_ID":"5","TERM":"cygwin","RBENV_SHELL":"bash","PATH":"/home/vagrant/.composer/vendor/bin:/usr/local/go/bin:/home/vagrant/.rbenv/plugins/ruby-build/bin:/home/vagrant/.rbenv/shims:/home/vagrant/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/vagrant/.dotnet/tools","S_COLORS":"auto","XDG_RUNTIME_DIR":"/run/user/1000","LANG":"en_US.UTF-8","LS_COLORS":"rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:","SHELL":"/bin/bash","LESSCLOSE":"/usr/bin/lesspipe %s %s","LC_ALL":"en_US.UTF-8","PWD":"/home/vagrant/code/ic_server_welfare","SSH_CONNECTION":"10.0.2.2 57778 10.0.2.15 22","XDG_DATA_DIRS":"/usr/local/share:/usr/share:/var/lib/snapd/desktop","PHP_SELF":"/home/vagrant/code/ic_server_welfare/artisan","SCRIPT_NAME":"/home/vagrant/code/ic_server_welfare/artisan","SCRIPT_FILENAME":"/home/vagrant/code/ic_server_welfare/artisan","PATH_TRANSLATED":"/home/vagrant/code/ic_server_welfare/artisan","DOCUMENT_ROOT":"","REQUEST_TIME_FLOAT":1565598725.529362,"REQUEST_TIME":1565598725,"argv":["/home/vagrant/code/ic_server_welfare/artisan","laravels","config","--daemonize"],"argc":4,"APP_ENV":"local","APP_DEBUG":"true","APP_KEY":"0uUBt7t4fFIttyqkyLxDhLC7gn9361Yt","APP_TIMEZONE":"UTC","DB_CONNECTION":"mysql","DB_HOST":"127.0.0.1","DB_PORT":"3306","DB_DATABASE":"ic_welfare","DB_USERNAME":"root","DB_PASSWORD":"root","CACHE_DRIVER":"file","QUEUE_DRIVER":"sync","SYSTEM_CODE":"09","SYSTEM_NAME":"IC业务助手福利中心服务","LARAVELS_LISTEN_IP":"0.0.0.0","LARAVELS_LISTEN_PORT":"61009","SHELL_VERBOSITY":0},"_ENV":{"APP_ENV":"local","APP_DEBUG":"true","APP_KEY":"0uUBt7t4fFIttyqkyLxDhLC7gn9361Yt","APP_TIMEZONE":"UTC","DB_CONNECTION":"mysql","DB_HOST":"127.0.0.1","DB_PORT":"3306","DB_DATABASE":"ic_welfare","DB_USERNAME":"root","DB_PASSWORD":"root","CACHE_DRIVER":"file","QUEUE_DRIVER":"sync","SYSTEM_CODE":"09","SYSTEM_NAME":"IC业务助手福利中心服务","LARAVELS_LISTEN_IP":"0.0.0.0","LARAVELS_LISTEN_PORT":"61009","SHELL_VERBOSITY":0}}}
\ No newline at end of file
2431
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment