Skip to content

Commit 05e8508

Browse files
Merge pull request NoiseByNorthwest#260 from NoiseByNorthwest/allow_zts
Allow ZTS PHP
2 parents 6e34e98 + d1e7923 commit 05e8508

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Current requirements are:
4141
* **GNU/Linux**, **macOS** or **FreeBSD**
4242
* zlib dev package (e.g. zlib1g-dev on Debian based distros)
4343
* PHP 5.4 to 8.3
44-
* Non-ZTS (threaded) build of PHP (ZTS support is theoretical)
4544

4645
## Installation
4746

@@ -67,6 +66,16 @@ sudo make install
6766
Then add `extension=spx.so` to your *php.ini*, or in a dedicated *spx.ini* file created within the include directory.
6867
You may also want to override [default SPX configuration](#configuration) to be able to profile a web request, with [this one](#private-environment) for example for a local development environment.
6968

69+
70+
### ZTS PHP (multi-thread)
71+
72+
ZTS PHP is supported, with these extra limitations:
73+
- a little overhead (theorically unnoticeable in most cases) is added when SPX is loaded, even if it is not enabled.
74+
- Ctrl-C a CLI script will not make the possible profiling session to be properly finished.
75+
- segfaults are more likely than for NTS PHP. In this regard, avoid more than ever mixing SPX with other instrumenting extensions (debuggers, profilers...).
76+
77+
Also, consider ZTS PHP support as still being in beta.
78+
7079
### Linux, PHP-FPM & I/O stats
7180

7281
On GNU/Linux, SPX uses procfs (i.e. by reading files under `/proc` directory) to get some stats for the current process or thread. This is what is done under the hood when you select at least one of these metrics: `mor`, `io`, `ior` or `iow`.
@@ -324,7 +333,7 @@ Here is the list below:
324333

325334
| Name | Default | Description |
326335
| ----- | -------- | ------------ |
327-
| _SPX_ENABLED_ | `0` | Whether to enable SPX profiler (i.e. triggering profiling). When disabled there is no performance impact on your application. |
336+
| _SPX_ENABLED_ | `0` | Whether to enable SPX profiler (i.e. triggering profiling). When disabled there is no performance impact on your application (except for ZTS PHP where a disabled SPX still adds a little overhead). |
328337
| _SPX_AUTO_START_ | `1` | Whether to enable SPX profiler's automatic start. When automatic start is disabled, you have to start & stop profiling on your own at runtime via the `spx_profiler_start()` & `spx_profiler_stop()` functions. [See here](#handle-long-living--daemon-processes) for more details. |
329338
| _SPX_BUILTINS_ | `0` | Whether to profile internal functions, script compilations, GC runs and request shutdown. |
330339
| _SPX_DEPTH_ | `0` | The stack depth at which profiling must stop (i.e. aggregate measures of deeper calls). 0 (default value) means unlimited. |

config.m4

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,9 @@ PHP_ARG_WITH(zlib-dir, for ZLIB,
1010
fi
1111

1212
if test "$PHP_SPX" = "yes"; then
13-
if test "$PHP_THREAD_SAFETY" != "no" -a "$CONTINUOUS_INTEGRATION" != "true"
14-
then
15-
AC_MSG_ERROR([SPX does not work with ZTS PHP build])
16-
fi
17-
1813
AC_DEFINE(HAVE_SPX, 1, [spx])
1914

2015
CFLAGS="-Werror -Wall -O3 -pthread -std=gnu90"
21-
if test "$CONTINUOUS_INTEGRATION" = "true"
22-
then
23-
CFLAGS="$CFLAGS -DCONTINUOUS_INTEGRATION"
24-
fi
2516

2617
if test "$PHP_SPX_DEV" = "yes"
2718
then

src/php_spx.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
# error "Only the following PHP versions are supported: 5.4 to 8.3"
3636
#endif
3737

38-
#if defined(ZTS) && !defined(CONTINUOUS_INTEGRATION)
39-
# error "ZTS is not yet supported"
40-
#endif
41-
4238
#define PHP_SPX_EXTNAME "SPX"
4339
#define PHP_SPX_VERSION "0.4.16"
4440

src/spx_utils.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
#include <stdio.h>
2020
#include <stdlib.h>
2121
#include <string.h>
22+
23+
#ifdef ZTS
24+
# include <pthread.h>
25+
#endif
26+
2227
#include "spx_utils.h"
2328

2429
char * spx_utils_resolve_confined_file_absolute_path(
@@ -162,13 +167,13 @@ int spx_utils_str_ends_with(const char * str, const char * suffix)
162167
return 0;
163168
}
164169

165-
#ifdef ZTS
166-
/* We just cannot kill other threads */
167-
# error "Fair error handling is required for ZTS"
168-
#endif
169170
void spx_utils_die_(const char * msg, const char * file, size_t line)
170171
{
171172
fprintf(stderr, "SPX Fatal error at %s:%lu - %s\n", file, line, msg);
172173

174+
#ifdef ZTS
175+
pthread_exit(NULL);
176+
#else
173177
exit(EXIT_FAILURE);
178+
#endif
174179
}

0 commit comments

Comments
 (0)