Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8b95ac

Browse files
author
Maarten de Boer
committed
Initial version
1 parent a02799c commit b8b95ac

13 files changed

Lines changed: 159 additions & 35 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
.idea/

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
[![last commit](https://img.shields.io/github/last-commit/mdeboer/ddev-php-spx)](https://github.com/mdeboer/ddev-php-spx/commits)
44
[![release](https://img.shields.io/github/v/release/mdeboer/ddev-php-spx)](https://github.com/mdeboer/ddev-php-spx/releases/latest)
55

6-
# DDEV Php Spx
6+
# DDEV php-spx (Simple Profiling eXtension)
77

88
## Overview
99

10-
This add-on integrates Php Spx into your [DDEV](https://ddev.com/) project.
10+
This add-on integrates [php-spx](https://github.com/NoiseByNorthwest/php-spx) (Simple Profiling eXtension) into
11+
your [DDEV](https://ddev.com/)
12+
project.
1113

1214
## Installation
1315

@@ -20,10 +22,14 @@ After installation, make sure to commit the `.ddev` directory to version control
2022

2123
## Usage
2224

23-
| Command | Description |
24-
| ------- | ----------- |
25-
| `ddev describe` | View service status and used ports for Php Spx |
26-
| `ddev logs -s php-spx` | Check Php Spx logs |
25+
| Command | Description |
26+
|-------------------|-------------------------------------------|
27+
| `ddev spx status` | See whether SPX extension has been loaded |
28+
| `ddev spx on` | Enable SPX extension |
29+
| `ddev spx off` | Disable SPX extension |
30+
31+
For information about the usage of SPX itself, please refer to the official documentation
32+
at https://github.com/NoiseByNorthwest/php-spx.
2733

2834
## Advanced Customization
2935

@@ -39,8 +45,8 @@ Make sure to commit the `.ddev/.env.php-spx` file to version control.
3945

4046
All customization options (use with caution):
4147

42-
| Variable | Flag | Default |
43-
| -------- | ---- | ------- |
48+
| Variable | Flag | Default |
49+
|------------------------|--------------------------|------------------------------|
4450
| `PHP_SPX_DOCKER_IMAGE` | `--php-spx-docker-image` | `ddev/ddev-utilities:latest` |
4551

4652
## Credits

commands/web/spx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
#ddev-generated
3+
4+
## Description: Toggle SPX (Simple Profiling eXtension)
5+
## Usage: spx on|off|enable|disable|toggle|status
6+
## Example: ddev spx on
7+
## ExecRaw: false
8+
## Flags: []
9+
## AutocompleteTerms: ["on", "off", "enable", "disable", "toggle", "status"]
10+
11+
case "${1:-status}" in
12+
on | enable)
13+
enable_spx
14+
;;
15+
off | disable)
16+
disable_spx
17+
;;
18+
toggle)
19+
if php -m | grep -qi spx; then
20+
disable_spx
21+
else
22+
enable_spx
23+
fi
24+
;;
25+
status)
26+
if php -m | grep -qi spx; then
27+
echo "SPX is enabled"
28+
else
29+
echo "SPX is disabled"
30+
fi
31+
;;
32+
*)
33+
echo "Invalid argument: $1"
34+
exit 1
35+
;;
36+
esac

docker-compose.php-spx.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

install.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: php-spx
22

33
project_files:
4-
- docker-compose.php-spx.yaml
4+
- commands/web/spx
5+
- php/25-spx.ini
6+
- web-build/disable_spx
7+
- web-build/Dockerfile.php-spx
8+
- web-build/enable_spx
9+
- web-build/prepend.Dockerfile.php-spx
10+
- web-build/z-www-overrides-spx.conf
511

612
ddev_version_constraint: '>= v1.24.3'

php/25-spx.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
;#ddev-generated
2+
3+
[PHP]
4+
spx.http_enabled=1
5+
spx.http_key="dev"
6+
spx.http_ip_whitelist="*"

tests/test.bats

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,30 @@ setup() {
3838
assert_success
3939
}
4040

41-
health_checks() {
42-
# Do something useful here that verifies the add-on
41+
ddev_spx_command_checks() {
42+
run ddev spx on
43+
assert_success
44+
assert_output --partial "SPX is enabled"
45+
46+
run ddev spx status
47+
assert_success
48+
assert_output --partial "SPX is enabled"
49+
50+
run ddev php -m
51+
assert_success
52+
assert_line SPX
53+
54+
run ddev spx off
55+
assert_success
56+
assert_output --partial "SPX is disabled"
4357

44-
# You can check for specific information in headers:
45-
# run curl -sfI https://${PROJNAME}.ddev.site
46-
# assert_output --partial "HTTP/2 200"
47-
# assert_output --partial "test_header"
58+
run ddev spx status
59+
assert_success
60+
assert_output --partial "SPX is disabled"
4861

49-
# Or check if some command gives expected output:
50-
DDEV_DEBUG=true run ddev launch
62+
run ddev php -m
5163
assert_success
52-
assert_output --partial "FULLURL https://${PROJNAME}.ddev.site"
64+
refute_line SPX
5365
}
5466

5567
teardown() {
@@ -71,7 +83,7 @@ teardown() {
7183
assert_success
7284
run ddev restart -y
7385
assert_success
74-
health_checks
86+
ddev_spx_command_checks
7587
}
7688

7789
# bats test_tags=release
@@ -82,5 +94,5 @@ teardown() {
8294
assert_success
8395
run ddev restart -y
8496
assert_success
85-
health_checks
97+
ddev_spx_command_checks
8698
}

tests/testdata/.gitmanaged

Whitespace-only changes.

web-build/Dockerfile.php-spx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ddev-generated
2+
3+
# Install runtime dependencies
4+
RUN DEBIAN_FRONTEND=noninteractive \
5+
&& apt-get update \
6+
&& apt-get install -y -o Dpkg::Options::="--force-confnew" --no-install-recommends --no-install-suggests \
7+
zlib1g \
8+
&& apt-get clean \
9+
&& rm -Rf /var/lib/apt/lists/*
10+
11+
# Copy php-spx module from build stage
12+
COPY --from=build-php-spx /tmp/php-spx/modules/spx.so /tmp/spx.so
13+
14+
RUN mv /tmp/spx.so $(php${DDEV_PHP_VERSION} -r 'echo ini_get("extension_dir");') \
15+
&& echo "extension=spx.so" > "/etc/php/${DDEV_PHP_VERSION}/mods-available/spx.ini"
16+
17+
# Copy FPM pool config
18+
ADD z-www-overrides-spx.conf /etc/php/$DDEV_PHP_VERSION/fpm/pool.d/
19+
20+
# Copy utilities
21+
ADD enable_spx disable_spx /usr/local/bin/

web-build/disable_spx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
#ddev-generated
3+
4+
phpdismod -v "$DDEV_PHP_VERSION" spx
5+
6+
case "$DDEV_WEBSERVER_TYPE" in
7+
"nginx-fpm" | "apache-fpm")
8+
killall -USR2 php-fpm 2>/dev/null || true
9+
;;
10+
esac
11+
12+
echo "SPX is disabled"

0 commit comments

Comments
 (0)