Skip to content

Allow ZTS PHP #260

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 1 commit into from
Sep 8, 2024
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
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Current requirements are:
* **GNU/Linux**, **macOS** or **FreeBSD**
* zlib dev package (e.g. zlib1g-dev on Debian based distros)
* PHP 5.4 to 8.3
* Non-ZTS (threaded) build of PHP (ZTS support is theoretical)

## Installation

Expand All @@ -67,6 +66,16 @@ sudo make install
Then add `extension=spx.so` to your *php.ini*, or in a dedicated *spx.ini* file created within the include directory.
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.


### ZTS PHP (multi-thread)

ZTS PHP is supported, with these extra limitations:
- a little overhead (theorically unnoticeable in most cases) is added when SPX is loaded, even if it is not enabled.
- Ctrl-C a CLI script will not make the possible profiling session to be properly finished.
- segfaults are more likely than for NTS PHP. In this regard, avoid more than ever mixing SPX with other instrumenting extensions (debuggers, profilers...).

Also, consider ZTS PHP support as still being in beta.

### Linux, PHP-FPM & I/O stats

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`.
Expand Down Expand Up @@ -324,7 +333,7 @@ Here is the list below:

| Name | Default | Description |
| ----- | -------- | ------------ |
| _SPX_ENABLED_ | `0` | Whether to enable SPX profiler (i.e. triggering profiling). When disabled there is no performance impact on your application. |
| _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). |
| _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. |
| _SPX_BUILTINS_ | `0` | Whether to profile internal functions, script compilations, GC runs and request shutdown. |
| _SPX_DEPTH_ | `0` | The stack depth at which profiling must stop (i.e. aggregate measures of deeper calls). 0 (default value) means unlimited. |
Expand Down
9 changes: 0 additions & 9 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,9 @@ PHP_ARG_WITH(zlib-dir, for ZLIB,
fi

if test "$PHP_SPX" = "yes"; then
if test "$PHP_THREAD_SAFETY" != "no" -a "$CONTINUOUS_INTEGRATION" != "true"
then
AC_MSG_ERROR([SPX does not work with ZTS PHP build])
fi

AC_DEFINE(HAVE_SPX, 1, [spx])

CFLAGS="-Werror -Wall -O3 -pthread -std=gnu90"
if test "$CONTINUOUS_INTEGRATION" = "true"
then
CFLAGS="$CFLAGS -DCONTINUOUS_INTEGRATION"
fi

if test "$PHP_SPX_DEV" = "yes"
then
Expand Down
4 changes: 0 additions & 4 deletions src/php_spx.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
# error "Only the following PHP versions are supported: 5.4 to 8.3"
#endif

#if defined(ZTS) && !defined(CONTINUOUS_INTEGRATION)
# error "ZTS is not yet supported"
#endif

#define PHP_SPX_EXTNAME "SPX"
#define PHP_SPX_VERSION "0.4.16"

Expand Down
13 changes: 9 additions & 4 deletions src/spx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef ZTS
# include <pthread.h>
#endif

#include "spx_utils.h"

char * spx_utils_resolve_confined_file_absolute_path(
Expand Down Expand Up @@ -162,13 +167,13 @@ int spx_utils_str_ends_with(const char * str, const char * suffix)
return 0;
}

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

#ifdef ZTS
pthread_exit(NULL);
#else
exit(EXIT_FAILURE);
#endif
}
Loading