Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -3273,6 +3273,12 @@ static zend_result accel_post_startup(void)
accel_startup_ok = false;
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - probably not enough shared memory.");
return SUCCESS;
case NO_SHM_BACKEND:
zend_accel_error(ACCEL_LOG_INFO, "Opcode Caching is disabled (No available SHM backend)");
zps_startup_failure("No available SHM backend", NULL, accelerator_remove_cb);
/* Do not abort PHP startup */
return SUCCESS;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Whitespace that isn't consistent with rest of switch cases. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get. You compile opcache into PHP just to say it can't work on this platform...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dstogov This comes after https://wiki.php.net/rfc/make_opcache_required. The aim is to consistently provide opcache without having to install it separately, and without having to load the extension, but keep PHP compatible with rare systems that don't support any of Opcache's backends.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, for these systems we provide a feature that can't work and just waste resources.
Note that compilation of opcache for these systems may be a problem as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we could at least make the file cache work, at least when opcache.file_cache is specified. In the long term, always building opcache will help reduce complexity and some inconsistencies, even if it ends up being disabled as in this PR, or by opcache.enable(_cli)=0.

I've measured the overhead of building opcache: It is about 110KiB of .text in a -Os build. The total size of the .text section in a minimal PHP build is about 6MiB.

Note that compilation of opcache for these systems may be a problem as well.

I'm happy making changes to address these problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Maybe it make sense to extend the error message with a suggestion to set opcache.enable=0 to "hide" it.

case SUCCESSFULLY_REATTACHED:
#ifdef HAVE_JIT
reattached = true;
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ PHP_ADD_EXTENSION_DEP(opcache, date)
PHP_ADD_EXTENSION_DEP(opcache, pcre)

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

Expand Down
3 changes: 3 additions & 0 deletions ext/opcache/zend_shared_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ int zend_shared_alloc_startup(size_t requested_size, size_t reserved_size)

if (!g_shared_alloc_handler) {
/* try memory handlers in order */
if (handler_table->name == NULL) {
return NO_SHM_BACKEND;
}
for (he = handler_table; he->name; he++) {
res = zend_shared_alloc_try(he, requested_size, &ZSMMG(shared_segments), &ZSMMG(shared_segments_count), &error_in);
if (res) {
Expand Down
1 change: 1 addition & 0 deletions ext/opcache/zend_shared_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#define SUCCESSFULLY_REATTACHED 4
#define ALLOC_FAIL_MAPPING 8
#define ALLOC_FALLBACK 9
#define NO_SHM_BACKEND 10

typedef struct _zend_shared_segment {
size_t size;
Expand Down