Skip to content

Commit e4078a6

Browse files
committed
Disable opcache if no SHM backend is available
Currently, configure fails when no SHM backend is available. Additionally, even after bypassing the configure check, opcache emits a fatal error if no SHM backend is available. Make the configure check non-fatal (a warning is printed). At runtime, disable opcache if no backend is available, in the same way we disable opcache by default on CLI. Closes GH-19350
1 parent fe88711 commit e4078a6

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,12 @@ static zend_result accel_post_startup(void)
32413241
accel_startup_ok = false;
32423242
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - probably not enough shared memory.");
32433243
return SUCCESS;
3244+
case NO_SHM_BACKEND:
3245+
zend_accel_error(ACCEL_LOG_INFO, "Opcode Caching is disabled: No available SHM backend. Set opcache.enable=0 to hide this message.");
3246+
zps_startup_failure("No available SHM backend", NULL, accelerator_remove_cb);
3247+
/* Do not abort PHP startup */
3248+
return SUCCESS;
3249+
32443250
case SUCCESSFULLY_REATTACHED:
32453251
#ifdef HAVE_JIT
32463252
reattached = true;

ext/opcache/config.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ PHP_ADD_EXTENSION_DEP(opcache, date)
346346
PHP_ADD_EXTENSION_DEP(opcache, pcre)
347347

348348
if test "$php_cv_shm_ipc" != "yes" && test "$php_cv_shm_mmap_posix" != "yes" && test "$php_cv_shm_mmap_anon" != "yes"; then
349-
AC_MSG_FAILURE(m4_text_wrap([
349+
AC_MSG_WARN(m4_text_wrap([
350350
No supported shared memory caching support was found when configuring
351-
opcache.
351+
opcache. Opcache will be disabled.
352352
]))
353353
fi
354354

ext/opcache/zend_shared_alloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ int zend_shared_alloc_startup(size_t requested_size, size_t reserved_size)
229229

230230
if (!g_shared_alloc_handler) {
231231
/* try memory handlers in order */
232+
if (handler_table->name == NULL) {
233+
return NO_SHM_BACKEND;
234+
}
232235
for (he = handler_table; he->name; he++) {
233236
res = zend_shared_alloc_try(he, requested_size, &ZSMMG(shared_segments), &ZSMMG(shared_segments_count), &error_in);
234237
if (res) {

ext/opcache/zend_shared_alloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#define SUCCESSFULLY_REATTACHED 4
7373
#define ALLOC_FAIL_MAPPING 8
7474
#define ALLOC_FALLBACK 9
75+
#define NO_SHM_BACKEND 10
7576

7677
typedef struct _zend_shared_segment {
7778
size_t size;

0 commit comments

Comments
 (0)