Skip to content

Php unix socket pr 1.x #724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions docs/roles/cache_clear/cache_clear-opcache.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Opcache

Clear opcache.
Clear opcache. You must have run the `cli/cachetool` role to install `cachetool` first.

<!--TOC-->
<!--ENDTOC-->
Expand All @@ -10,16 +10,11 @@ Clear opcache.
```yaml
---
cache_clear_opcache:
# Adapter string to use as argument.
# eg.
# --fcgi=127.0.0.1:9000
# Leave blank to use /etc/cachetool.yml
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
# Bins to clear.
clear_opcache: true
clear_apcu: false
clear_stat: true
# cachetool_bin: "/path/to/cachetool.phar" # see _init for paths if undefined
# cachetool_bin: "/path/to/cachetool.phar" # see _init for default paths if undefined

```

Expand Down
7 changes: 7 additions & 0 deletions docs/roles/cli/cachetool.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Installs the `drush` command-line tool for the deploy user.
---
cachetool:
version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version.
unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision
# Adapter string to use as argument.
# e.g.
# --fcgi=127.0.0.1:9000
# --fcgi=/var/run/php-fpm.sock
# Provide an empty string to use /etc/cachetool.yml
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.

```

Expand Down
9 changes: 2 additions & 7 deletions roles/cache_clear/cache_clear-opcache/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Opcache

Clear opcache.
Clear opcache. You must have run the `cli/cachetool` role to install `cachetool` first.

<!--TOC-->
<!--ENDTOC-->
Expand All @@ -10,16 +10,11 @@ Clear opcache.
```yaml
---
cache_clear_opcache:
# Adapter string to use as argument.
# eg.
# --fcgi=127.0.0.1:9000
# Leave blank to use /etc/cachetool.yml
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
# Bins to clear.
clear_opcache: true
clear_apcu: false
clear_stat: true
# cachetool_bin: "/path/to/cachetool.phar" # see _init for paths if undefined
# cachetool_bin: "/path/to/cachetool.phar" # see _init for default paths if undefined

```

Expand Down
7 changes: 0 additions & 7 deletions roles/cache_clear/cache_clear-opcache/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
---
cache_clear_opcache:
# Adapter string to use as argument.
# e.g.
# --fcgi=127.0.0.1:9000
# --fcgi=/var/run/php-fpm.sock
# Provide an empty string to use /etc/cachetool.yml
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision
# Bins to clear.
clear_opcache: true
clear_apcu: false
Expand Down
18 changes: 0 additions & 18 deletions roles/cache_clear/cache_clear-opcache/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
---
- name: Get latest php installed
ansible.builtin.shell:
cmd: 'set -o pipefail && ls -1 /etc/php/ | while read ver; do if [ -d "/etc/php/$ver/fpm" ]; then echo "$ver"; fi; done | tail -1'
args:
executable: /bin/bash
register: _php_version

- name: Set cachetool adapter specified or default to a TCP/IP port.
ansible.builtin.set_fact:
_cachetool_adapter: "{{ cache_clear_opcache.adapter | default('--fcgi=127.0.0.1:90' + _php_version.stdout | replace('.','')) }}"

- name: Override cachetool adapter to be a Unix socket if requested.
ansible.builtin.set_fact:
_cachetool_adapter: "--fcgi=/var/run/php{{ _php_version.stdout | replace('.','') }}-fpm.sock"
when:
- cache_clear_opcache.unix_socket
- cache_clear_opcache.adapter is not defined

# cachetool_bin is set in the _init role.
- name: Clear opcache.
ansible.builtin.command:
Expand Down
7 changes: 7 additions & 0 deletions roles/cli/cachetool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Installs the `drush` command-line tool for the deploy user.
---
cachetool:
version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version.
unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision
# Adapter string to use as argument.
# e.g.
# --fcgi=127.0.0.1:9000
# --fcgi=/var/run/php-fpm.sock
# Provide an empty string to use /etc/cachetool.yml
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.

```

Expand Down
7 changes: 7 additions & 0 deletions roles/cli/cachetool/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---
cachetool:
version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version.
unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision
# Adapter string to use as argument.
# e.g.
# --fcgi=127.0.0.1:9000
# --fcgi=/var/run/php-fpm.sock
# Provide an empty string to use /etc/cachetool.yml
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
24 changes: 24 additions & 0 deletions roles/cli/cachetool/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,27 @@
- deploy_operation == 'deploy'
- cachetool.version is defined
- cachetool.version | length > 0

# Set up cachetool adapter
- name: Get latest PHP version installed.
ansible.builtin.shell:
cmd: 'set -o pipefail && ls -1 /etc/php/ | while read ver; do if [ -d "/etc/php/$ver/fpm" ]; then echo "$ver"; fi; done | tail -1'
args:
executable: /bin/bash
register: _php_version

- name: Set cachetool adapter specified or default to a TCP/IP port.
ansible.builtin.set_fact:
_cachetool_adapter: "{{ cachetool.adapter | default('--fcgi=127.0.0.1:90' + _php_version.stdout | replace('.','')) }}"

- name: Override cachetool adapter to be a Unix socket if requested.
ansible.builtin.set_fact:
_cachetool_adapter: "--fcgi=/var/run/php{{ _php_version.stdout | replace('.','') }}-fpm.sock"
when:
- cachetool.unix_socket
- cachetool.adapter is not defined

# We want to fail early if cachetool is broken.
- name: Ensure cachetool is working.
ansible.builtin.command:
cmd: "{{ cachetool_bin }} {{ _cachetool_adapter }} -n opcache:status"