Skip to content

Commit a8c8704

Browse files
committed
Switched to php-cgi-spawner, better messages, minor code cleanup
1 parent 834173a commit a8c8704

8 files changed

+69
-38
lines changed

README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ Installation
88

99
1. Clone `https://github.com/samdark/wnmp-dev.git` or [download as archive](https://github.com/samdark/wnmp-dev/archive/master.zip).
1010
2. Download PHP [from PHP for Windows website](http://windows.php.net/download/). You need `nts` and `x86` zip.
11-
3. Extract archive. PHP 5.5 should end up in `php55`, PHP 5.4 should end up in `php54`.
12-
4. Download [MariaDB](https://downloads.mariadb.org/) or [MySQL](https://dev.mysql.com/downloads/windows/installer/), put it to `mariadb`.
11+
3. Extract archive. PHP 5.5 should end up in `php55`, PHP 5.4 should end up in `php54` etc.
12+
4. Download [MariaDB](https://downloads.mariadb.org/) or [MySQL](https://dev.mysql.com/downloads/windows/installer/),
13+
put it to `mariadb`.
1314
5. Copy `nginx/conf/vhosts/example._conf` to `nginx/conf/vhosts/mysite.conf`, edit it to point to your webroot.
1415
6. Add domain chosen to your hosts file.
1516
7. Run `start_all.bat`.
@@ -18,11 +19,12 @@ Installation
1819
Switching PHP versions
1920
----------------------
2021

21-
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
22-
new directories for these and then you'll be able to run `restart php-directory`.
22+
By default it starts 4 instances of PHP 7 FastCGI on port 9000 but it's possible to switch versions by running
23+
`restart_php php54`. It's also possible to specify number of `php-cgi.exe` instances and port via
24+
`restart_php php54 4 9000`. If you need another PHP version create new directory `php-directory` for it, put PHP there
25+
and then you'll be able to run `restart php-directory`.
26+
27+
Credits
28+
-------
2329

24-
Known issues
25-
------------
26-
27-
- php-cgi can handle a single request at a time. Since running multiple php-cgi results in frequent crashing and impossibility to debug with
28-
XDebug we're sticking to a single php-cgi instance. If you need better performance using Windows consider switching to Apache or IIS.
30+
- PHP CGI spawner (`php-cgi-spawner.exe`): https://github.com/deemru/php-cgi-spawner

README_RU.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ wnmp-dev — среда окружения под Windows, содержащая
99

1010
1. Клонируем `https://github.com/samdark/wnmp-dev.git` или [загружаем архивом](https://github.com/samdark/wnmp-dev/archive/master.zip).
1111
2. Забираем нужные версии PHP [с сайта PHP for Windows](http://windows.php.net/download/). Берите `nts`, `x86` в zip-архиве.
12-
3. Распаковываем архив. Версия 5.5 должна оказаться в `php55`, версия 5.4 в `php54`.
12+
3. Распаковываем архив. Версия 5.5 должна оказаться в `php55`, версия 5.4 в `php54` и т.д.
1313
4. Забираем [MariaDB](https://downloads.mariadb.org/) или [MySQL](https://dev.mysql.com/downloads/windows/installer/), складываем в `mariadb`.
1414
5. Копируем `nginx/conf/vhosts/example._conf` в `nginx/conf/vhosts/mysite.conf`, редактируем так, чтобы конфиг указывал корневой веб-каталог.
1515
6. Добавляем домен из конфига в hosts.
@@ -19,11 +19,11 @@ wnmp-dev — среда окружения под Windows, содержащая
1919
Переключение версий PHP
2020
-----------------------
2121

22-
По умолчанию стартует PHP 5.5, но можно переключить версию запуском `restart_php php54`.
23-
Если вам нужно больше версий, создайте новые каталоги для них и запустите `restart php-directory`.
22+
По умолчанию стартует четыре инстанса PHP 7 FastCGI на 9000 порту, но можно переключить версию запуском `restart_php php54`.
23+
Также можно указать количество инстансов `php-cgi.exe` и порт как `restart_php php54 4 9000`. Если вам нужна ещё одна
24+
версия PHP, создайте `php-directory` и положите туда PHP. После этого вы можете запустить `restart php-directory`.
2425

25-
Известные проблемы
26-
------------------
26+
В проекте используется
27+
----------------------
2728

28-
- php-cgi может обрабатывать один запрос за раз. Поскольку запуск нескольких экземпляров php-cgi ведёт к частым сбоям и невозможности отладки в XDebug,
29-
мы привязываемся к одному экземпляру php-cgi. Если вам нужна хорошая производительность в Windows, лучше использовать Apache или IIS.
29+
- PHP CGI spawner (`php-cgi-spawner.exe`): https://github.com/deemru/php-cgi-spawner

nginx/conf/nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#user nobody;
2-
worker_processes 1;
2+
worker_processes 4;
33

44
error_log logs/error.log warn;
55
pid logs/nginx.pid;

php-cgi-spawner.exe

4 KB
Binary file not shown.

php7/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Put PHP 7 nts here

restart_php.bat

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1-
@IF [%1] == [] GOTO usage
1+
@echo off
22

3-
@taskkill /im php-cgi.exe /F > NUL
4-
@set PHP_FCGI_MAX_REQUESTS=0
5-
@start "PHP %1 FastCGI" /B "%1\php-cgi.exe" -b localhost:9000
6-
@echo Started PHP %1 FastCGI on port 9000.
3+
IF [%~1] == [] GOTO usage
74

8-
@GOTO :EOF
5+
if [%~2] == [] (
6+
set cgi_port=9000
7+
) else (
8+
set cgi_port=%~2
9+
)
10+
11+
if [%~3] == [] (
12+
set cgi_instances=4
13+
) else (
14+
set cgi_instances=%~3
15+
)
16+
17+
taskkill /im php-cgi-spawner.exe /F > NUL 2>&1
18+
taskkill /im php-cgi.exe /F > NUL 2>&1
19+
20+
21+
@rem set PHP_FCGI_MAX_REQUESTS=0
22+
@rem start "PHP %1 FastCGI" /B "%1\php-cgi.exe" -b localhost:%cgi_port%
23+
24+
start "PHP %1 FastCGI Spawner" /B "php-cgi-spawner.exe" %1/php-cgi.exe %cgi_port% %cgi_instances%
25+
26+
echo Started %cgi_instances% PHP %1 FastCGI on port %cgi_port%.
27+
28+
GOTO :EOF
929

1030
:usage
11-
@echo Kills existing php-cgi processes and then starts specified process from directory specified.
12-
@echo Usage is "restart_php php55" to start php-cgi from php55 directory.
31+
echo Kills existing php-cgi processes and then starts specified process from directory specified.
32+
echo Usage is "restart_php php55" to start php-cgi from php55 directory.
33+
echo You could also specify number of instances to spawn and a port to bind to "restart_php php55 4 9000".

start_all.bat

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
@call restart_php php55
1+
@echo off
22

3-
@pushd nginx
4-
@start "nginx" /B "nginx.exe"
5-
@popd
6-
@echo Started nginx.
3+
call restart_php php7
74

8-
@start "MariaDB" /B "mariadb\bin\mysqld.exe" "--defaults-file=mariadb\data\my.ini"
9-
@echo Started MariaDB.
5+
pushd nginx
6+
start "nginx" /B "nginx.exe"
7+
popd
8+
echo Started nginx.
9+
10+
start "MariaDB" /B "mariadb\bin\mysqld.exe" "--defaults-file=mariadb\data\my.ini"
11+
echo Started MariaDB.

stop_all.bat

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
@echo Killing php-cgi.
2-
@taskkill /im php-cgi.exe /F > NUL
1+
@echo off
32

4-
@echo Killing nginx.
5-
@taskkill /im nginx.exe /F > NUL
3+
echo Killing php-cgi spawner.
4+
taskkill /im php-cgi-spawner.exe /F > NUL 2>&1
65

7-
@echo Stopping MariaDB.
8-
@mariadb\bin\mysqladmin -u root shutdown
6+
echo Killing php-cgi.
7+
taskkill /im php-cgi.exe /F > NUL 2>&1
8+
9+
echo Killing nginx.
10+
taskkill /im nginx.exe /F > NUL 2>&1
11+
12+
echo Stopping MariaDB.
13+
mariadb\bin\mysqladmin -u root shutdown

0 commit comments

Comments
 (0)