From a8c8704f211ecffc8dbe5f91da2c42699d54f9c1 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Wed, 16 Dec 2015 18:45:37 +0300 Subject: [PATCH] Switched to php-cgi-spawner, better messages, minor code cleanup --- README.md | 20 +++++++++++--------- README_RU.md | 14 +++++++------- nginx/conf/nginx.conf | 2 +- php-cgi-spawner.exe | Bin 0 -> 4096 bytes php7/README.md | 1 + restart_php.bat | 37 +++++++++++++++++++++++++++++-------- start_all.bat | 16 +++++++++------- stop_all.bat | 17 +++++++++++------ 8 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 php-cgi-spawner.exe create mode 100644 php7/README.md diff --git a/README.md b/README.md index 6d6f347..95b925e 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ Installation 1. Clone `https://github.com/samdark/wnmp-dev.git` or [download as archive](https://github.com/samdark/wnmp-dev/archive/master.zip). 2. Download PHP [from PHP for Windows website](http://windows.php.net/download/). You need `nts` and `x86` zip. -3. Extract archive. PHP 5.5 should end up in `php55`, PHP 5.4 should end up in `php54`. -4. Download [MariaDB](https://downloads.mariadb.org/) or [MySQL](https://dev.mysql.com/downloads/windows/installer/), put it to `mariadb`. +3. Extract archive. PHP 5.5 should end up in `php55`, PHP 5.4 should end up in `php54` etc. +4. Download [MariaDB](https://downloads.mariadb.org/) or [MySQL](https://dev.mysql.com/downloads/windows/installer/), + put it to `mariadb`. 5. Copy `nginx/conf/vhosts/example._conf` to `nginx/conf/vhosts/mysite.conf`, edit it to point to your webroot. 6. Add domain chosen to your hosts file. 7. Run `start_all.bat`. @@ -18,11 +19,12 @@ Installation Switching PHP versions ---------------------- -By default it starts PHP 5.5 but it's possible to switch versions by running `restart_php php54`. If you need more PHP versions create -new directories for these and then you'll be able to run `restart php-directory`. +By default it starts 4 instances of PHP 7 FastCGI on port 9000 but it's possible to switch versions by running +`restart_php php54`. It's also possible to specify number of `php-cgi.exe` instances and port via +`restart_php php54 4 9000`. If you need another PHP version create new directory `php-directory` for it, put PHP there +and then you'll be able to run `restart php-directory`. + +Credits +------- -Known issues ------------- - -- php-cgi can handle a single request at a time. Since running multiple php-cgi results in frequent crashing and impossibility to debug with - XDebug we're sticking to a single php-cgi instance. If you need better performance using Windows consider switching to Apache or IIS. +- PHP CGI spawner (`php-cgi-spawner.exe`): https://github.com/deemru/php-cgi-spawner diff --git a/README_RU.md b/README_RU.md index c231f27..833c314 100644 --- a/README_RU.md +++ b/README_RU.md @@ -9,7 +9,7 @@ wnmp-dev — среда окружения под Windows, содержащая 1. Клонируем `https://github.com/samdark/wnmp-dev.git` или [загружаем архивом](https://github.com/samdark/wnmp-dev/archive/master.zip). 2. Забираем нужные версии PHP [с сайта PHP for Windows](http://windows.php.net/download/). Берите `nts`, `x86` в zip-архиве. -3. Распаковываем архив. Версия 5.5 должна оказаться в `php55`, версия 5.4 в `php54`. +3. Распаковываем архив. Версия 5.5 должна оказаться в `php55`, версия 5.4 в `php54` и т.д. 4. Забираем [MariaDB](https://downloads.mariadb.org/) или [MySQL](https://dev.mysql.com/downloads/windows/installer/), складываем в `mariadb`. 5. Копируем `nginx/conf/vhosts/example._conf` в `nginx/conf/vhosts/mysite.conf`, редактируем так, чтобы конфиг указывал корневой веб-каталог. 6. Добавляем домен из конфига в hosts. @@ -19,11 +19,11 @@ wnmp-dev — среда окружения под Windows, содержащая Переключение версий PHP ----------------------- -По умолчанию стартует PHP 5.5, но можно переключить версию запуском `restart_php php54`. -Если вам нужно больше версий, создайте новые каталоги для них и запустите `restart php-directory`. +По умолчанию стартует четыре инстанса PHP 7 FastCGI на 9000 порту, но можно переключить версию запуском `restart_php php54`. +Также можно указать количество инстансов `php-cgi.exe` и порт как `restart_php php54 4 9000`. Если вам нужна ещё одна +версия PHP, создайте `php-directory` и положите туда PHP. После этого вы можете запустить `restart php-directory`. -Известные проблемы ------------------- +В проекте используется +---------------------- -- php-cgi может обрабатывать один запрос за раз. Поскольку запуск нескольких экземпляров php-cgi ведёт к частым сбоям и невозможности отладки в XDebug, - мы привязываемся к одному экземпляру php-cgi. Если вам нужна хорошая производительность в Windows, лучше использовать Apache или IIS. +- PHP CGI spawner (`php-cgi-spawner.exe`): https://github.com/deemru/php-cgi-spawner diff --git a/nginx/conf/nginx.conf b/nginx/conf/nginx.conf index db300e8..549cea1 100644 --- a/nginx/conf/nginx.conf +++ b/nginx/conf/nginx.conf @@ -1,5 +1,5 @@ #user nobody; -worker_processes 1; +worker_processes 4; error_log logs/error.log warn; pid logs/nginx.pid; diff --git a/php-cgi-spawner.exe b/php-cgi-spawner.exe new file mode 100644 index 0000000000000000000000000000000000000000..f89b368279038940bd81a32dcb21c277623dc032 GIT binary patch literal 4096 zcmeHJZ){Ul6hCh(a|5=Pu_}DQw+UoXnQJ>t2qbi_9RpS<6gD*IEZbvk>Dr}zk3Sy< z#l8Yv)5s?^(GWk7_(4A*CisVD8p0rvNERd{jekJ{4rL}NT~hb_-P^uxk|8F1k%XI^ zd+z<6bAI>S^X`4`xn4R-r9@(#5Nj4r>ty&&^5 zpATk!gU;<=lKGMAc}4v=*PH#_J{F^A=ynpd3#D}Ynd@71?0YH^<_NP3n=3D%t4z>L zL^ih<#wA3vNMOLE<^^CyK`SA9f;+M}7R>deVj#U!O|*&)M54B09GgzIMk0OBlh}V5 zU@gvj58nn^+AG7BVGohz#n!%SeUa$ZhDbEh4HM4|0F^+>945@%bA(aqj+nTz0 z@TLg|&(qPVnGGg84VGI+tXbQi>UpEO9AWB+vNSd>%8O#-74pLPguxhJ1bE_$*m#{% z`k`P?IzGBKT5lg+!hpGI)~HV49$K@bRccnb&O&D)RQc9Aa>QhB9V}PREAOi#ve3%7 z5+m?UxyIsBo<`@Tw&t66jm$P?hSH9bi%DmGP*8`I8!6XKTXu9#^R6s6Z7;pZ@mncp zzAc_xZ9JR?Njfo>*EDyaqzfBq#6}WB#)Qn+my4LW145^EIiAyuY8L~CJv)=mOT*49 z2Z#jC{487oWXraAI)Pu-E~m!gUui4v7*z|r1BSFS=METr?Dg7_d^x9?>kBI!sb*$V z+Ih*{p_vy0Tsdr1|3YQqs~rH=RK#uo^Y~&YwPvm<1gl>I`u}yBb z56tBO!R^+R>mZz4AY7&?=L$qA=b2;~=g9=L0P4#Y zr3D`|-Hnb@OGNU@I?zmX$I$8Z%dO#vO9{&U{-CsRM?mV9afRXrkEAc)@hNgocu&af z#Ya<;r3mbssU;YWN^Mv&DA9W7<_*qvo3)`Q7$oZSSiAJ`3>$wSsFeQ;)Z>1$SH2yZ zm3Le5zE4pL{A<}i1CHBGM`plroao&d@CtmZ^nZ@&{0u)g1r$dDG5iWV>af)d|3>OWz`YLWHO;Q@JbhoT~pEoTL*cl3%wI3)kAA(BW=KZ zE&5iBSvzgGHNiNHkZSyB=z2A`&fGS=PNga~7%R9s*Av{0Tfh$TH-`yp~}- zJr@bF4e;5^{p@@%ZeU@orNCcCWp$SO@en zXFOGH_Rng7#}-(GiBITw@N8+QV7_yzCYu_jQf)EwvVhMX?N8j#*AvDy? NUL -@set PHP_FCGI_MAX_REQUESTS=0 -@start "PHP %1 FastCGI" /B "%1\php-cgi.exe" -b localhost:9000 -@echo Started PHP %1 FastCGI on port 9000. +IF [%~1] == [] GOTO usage -@GOTO :EOF +if [%~2] == [] ( + set cgi_port=9000 +) else ( + set cgi_port=%~2 +) + +if [%~3] == [] ( + set cgi_instances=4 +) else ( + set cgi_instances=%~3 +) + +taskkill /im php-cgi-spawner.exe /F > NUL 2>&1 +taskkill /im php-cgi.exe /F > NUL 2>&1 + + +@rem set PHP_FCGI_MAX_REQUESTS=0 +@rem start "PHP %1 FastCGI" /B "%1\php-cgi.exe" -b localhost:%cgi_port% + +start "PHP %1 FastCGI Spawner" /B "php-cgi-spawner.exe" %1/php-cgi.exe %cgi_port% %cgi_instances% + +echo Started %cgi_instances% PHP %1 FastCGI on port %cgi_port%. + +GOTO :EOF :usage -@echo Kills existing php-cgi processes and then starts specified process from directory specified. -@echo Usage is "restart_php php55" to start php-cgi from php55 directory. \ No newline at end of file +echo Kills existing php-cgi processes and then starts specified process from directory specified. +echo Usage is "restart_php php55" to start php-cgi from php55 directory. +echo You could also specify number of instances to spawn and a port to bind to "restart_php php55 4 9000". \ No newline at end of file diff --git a/start_all.bat b/start_all.bat index 3c33841..1f5b12a 100644 --- a/start_all.bat +++ b/start_all.bat @@ -1,9 +1,11 @@ -@call restart_php php55 +@echo off -@pushd nginx -@start "nginx" /B "nginx.exe" -@popd -@echo Started nginx. +call restart_php php7 -@start "MariaDB" /B "mariadb\bin\mysqld.exe" "--defaults-file=mariadb\data\my.ini" -@echo Started MariaDB. \ No newline at end of file +pushd nginx +start "nginx" /B "nginx.exe" +popd +echo Started nginx. + +start "MariaDB" /B "mariadb\bin\mysqld.exe" "--defaults-file=mariadb\data\my.ini" +echo Started MariaDB. \ No newline at end of file diff --git a/stop_all.bat b/stop_all.bat index c830842..4447666 100644 --- a/stop_all.bat +++ b/stop_all.bat @@ -1,8 +1,13 @@ -@echo Killing php-cgi. -@taskkill /im php-cgi.exe /F > NUL +@echo off -@echo Killing nginx. -@taskkill /im nginx.exe /F > NUL +echo Killing php-cgi spawner. +taskkill /im php-cgi-spawner.exe /F > NUL 2>&1 -@echo Stopping MariaDB. -@mariadb\bin\mysqladmin -u root shutdown \ No newline at end of file +echo Killing php-cgi. +taskkill /im php-cgi.exe /F > NUL 2>&1 + +echo Killing nginx. +taskkill /im nginx.exe /F > NUL 2>&1 + +echo Stopping MariaDB. +mariadb\bin\mysqladmin -u root shutdown