Skip to content

Commit

Permalink
Switched to php-cgi-spawner, better messages, minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Dec 16, 2015
1 parent 834173a commit a8c8704
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 38 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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
14 changes: 7 additions & 7 deletions README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#user nobody;
worker_processes 1;
worker_processes 4;

error_log logs/error.log warn;
pid logs/nginx.pid;
Expand Down
Binary file added php-cgi-spawner.exe
Binary file not shown.
1 change: 1 addition & 0 deletions php7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put PHP 7 nts here
37 changes: 29 additions & 8 deletions restart_php.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
@IF [%1] == [] GOTO usage
@echo off

@taskkill /im php-cgi.exe /F > 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.
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".
16 changes: 9 additions & 7 deletions start_all.bat
Original file line number Diff line number Diff line change
@@ -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.
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.
17 changes: 11 additions & 6 deletions stop_all.bat
Original file line number Diff line number Diff line change
@@ -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
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

0 comments on commit a8c8704

Please sign in to comment.