Skip to content

Commit b5721b8

Browse files
authored
Add php-fpm as a contrib recipe (#2487)
* Add php-fpm as a contrib recipe * Update CHANGELOG.md * Find the PHP-fpm version from the process
1 parent b4fcfa1 commit b5721b8

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Added slack_channel option to Slack recipe.
2424
- Chatwork contrib recipe.
2525
- Added `release_or_current_path` option that fallbacks to the `current_path` when the `release_path` does not exist. [#2486]
26+
- Added `contrib/php-fpm.php` recipe that provides a task to reload PHP-fpm. [#2487]
2627

2728
### Changed
2829
- Refactored executor engine, up to 2x faster than before.
@@ -603,6 +604,7 @@
603604
- Fixed `DotArray` syntax in `Collection`.
604605

605606

607+
[#2487]: https://github.com/deployphp/deployer/pull/2487
606608
[#2486]: https://github.com/deployphp/deployer/pull/2486
607609
[#2425]: https://github.com/deployphp/deployer/pull/2425
608610
[#2423]: https://github.com/deployphp/deployer/issues/2423

contrib/php-fpm.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/*
3+
## Installing
4+
5+
Add to your _deploy.php_
6+
7+
```php
8+
require 'contrib/php-fpm.php';
9+
```
10+
11+
## Configuration
12+
13+
- `php_fpm_version` – The PHP-fpm version. For example: `8.0`.
14+
- `php_fpm_service` – The full name of the PHP-fpm service. Defaults to `php{{php_fpm_version}}-fpm`.
15+
- `php_fpm_command` – The command to run to reload PHP-fpm. Defaults to `echo "" | sudo -S /usr/sbin/service {{php_fpm_service}} reload`.
16+
17+
## Usage
18+
19+
Start by explicitely providing the current version of PHP-version using the `php_fpm_version`.
20+
Alternatively, you may use any of the options above to configure how PHP-fpm should reload.
21+
22+
Then, add the `php-fpm:reload` task at the end of your deployments by using the `after` method like so.
23+
24+
```php
25+
set('php_fpm_version', '8.0');
26+
after('deploy', 'php-fpm:reload');
27+
```
28+
29+
*/
30+
namespace Deployer;
31+
32+
set('php_fpm_version', function () {
33+
$phpFpmProcess = run("ps aux | grep php-fpm | grep 'master process'");
34+
35+
if (! preg_match('/^.*master process.*(\d\.\d).*$/', $phpFpmProcess, $match)) {
36+
throw new \Exception('Please provide the PHP-fpm version using the `php_fpm_version` option.');
37+
}
38+
39+
return $match[1];
40+
});
41+
set('php_fpm_service', 'php{{php_fpm_version}}-fpm');
42+
set('php_fpm_command', 'echo "" | sudo -S /usr/sbin/service {{php_fpm_service}} reload');
43+
44+
desc('Reload the php-fpm service');
45+
task('php-fpm:reload', function () {
46+
run('{{php_fpm_command}}');
47+
});

docs/contrib/php-fpm.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!-- DO NOT EDIT THIS FILE! -->
2+
<!-- Instead edit contrib/php-fpm.php -->
3+
<!-- Then run bin/docgen -->
4+
5+
# php-fpm
6+
7+
[Source](/contrib/php-fpm.php)
8+
9+
10+
## Installing
11+
12+
Add to your _deploy.php_
13+
14+
```php
15+
require 'contrib/php-fpm.php';
16+
```
17+
18+
## Configuration
19+
20+
- `php_fpm_version` – The PHP-fpm version. For example: `8.0`.
21+
- `php_fpm_service` – The full name of the PHP-fpm service. Defaults to `php{{php_fpm_version}}-fpm`.
22+
- `php_fpm_command` – The command to run to reload PHP-fpm. Defaults to `echo "" | sudo -S /usr/sbin/service {{php_fpm_service}} reload`.
23+
24+
## Usage
25+
26+
Start by explicitely providing the current version of PHP-version using the `php_fpm_version`.
27+
Alternatively, you may use any of the options above to configure how PHP-fpm should reload.
28+
29+
Then, add the `php-fpm:reload` task at the end of your deployments by using the `after` method like so.
30+
31+
```php
32+
set('php_fpm_version', '8.0');
33+
after('deploy', 'php-fpm:reload');
34+
```
35+
36+
37+
38+
* Config
39+
* [`php_fpm_version`](#php_fpm_version)
40+
* [`php_fpm_service`](#php_fpm_service)
41+
* [`php_fpm_command`](#php_fpm_command)
42+
43+
## Config
44+
### php_fpm_version
45+
[Source](https://github.com/deployphp/deployer/search?q=%22php_fpm_version%22+in%3Afile+language%3Aphp+path%3Acontrib+filename%3Aphp-fpm.php)
46+
47+
48+
49+
### php_fpm_service
50+
[Source](https://github.com/deployphp/deployer/search?q=%22php_fpm_service%22+in%3Afile+language%3Aphp+path%3Acontrib+filename%3Aphp-fpm.php)
51+
52+
53+
54+
### php_fpm_command
55+
[Source](https://github.com/deployphp/deployer/search?q=%22php_fpm_command%22+in%3Afile+language%3Aphp+path%3Acontrib+filename%3Aphp-fpm.php)
56+
57+
58+
59+

0 commit comments

Comments
 (0)