Skip to content

Fixed GH-22216: don't warn in OnUpdateMemoryConsumption on ZTS thread init - #22225

Open
dkkoma wants to merge 1 commit into
php:PHP-8.5from
dkkoma:fix-gh-22216-opcache-memcons-zts
Open

Fixed GH-22216: don't warn in OnUpdateMemoryConsumption on ZTS thread init#22225
dkkoma wants to merge 1 commit into
php:PHP-8.5from
dkkoma:fix-gh-22216-opcache-memcons-zts

Conversation

@dkkoma

@dkkoma dkkoma commented Jun 4, 2026

Copy link
Copy Markdown

Fixes GH-22216

Testing

Put this as /tmp/ztsrepro/repro_min.c

#include <sapi/embed/php_embed.h>
#include <pthread.h>

static void *worker(void *arg)
{
    ts_resource(0);
    php_request_startup();
    php_printf("[worker] ");
    zend_eval_string("echo opcache_get_configuration()['directives']['opcache.memory_consumption'], PHP_EOL;", NULL, "w");
    php_request_shutdown(NULL);
    ts_free_thread();
    return NULL;
}

int main(int argc, char **argv)
{
    php_embed_init(argc, argv);
    php_printf("[main]   ");
    zend_eval_string("echo opcache_get_configuration()['directives']['opcache.memory_consumption'], PHP_EOL;", NULL, "m");
    pthread_t t;
    pthread_create(&t, NULL, worker, NULL);
    pthread_join(t, NULL);
    php_embed_shutdown();
    return 0;
}

Build php-src with --enable-zts --enable-embed, Run the following from the build root

cc /tmp/ztsrepro/repro_min.c -o /tmp/ztsrepro/repro_min -I. -Imain -IZend -ITSRM -Isapi/embed -Iext/date/lib -D_GNU_SOURCE -DZTS -DZEND_SIGNALS -DNDEBUG -pthread -Llibs -lphp -Wl,-rpath,libs

ini

echo 'opcache.log_verbosity_level=2' > /tmp/ztsrepro/opcache.ini

before

$ PHPRC=/tmp/ztsrepro/opcache.ini /tmp/ztsrepro/repro_min
[main]   134217728
Thu Jun  4 16:35:49 2026 (6129397760): Warning opcache.memory_consumption cannot be changed when OPcache is already set up.

[worker] 0

after

$ PHPRC=/tmp/ztsrepro/opcache.ini /tmp/ztsrepro/repro_min
[main]   134217728
[worker] 134217728

@dkkoma
dkkoma requested a review from dstogov as a code owner June 4, 2026 08:11
@dkkoma
dkkoma force-pushed the fix-gh-22216-opcache-memcons-zts branch from b56e49d to 57bacf8 Compare August 15, 2026 12:16
@dkkoma

dkkoma commented Aug 15, 2026

Copy link
Copy Markdown
Author

The previous CI failure appeared to be unrelated to this change. I've rebased the branch onto the latest PHP-8.5, and all checks are passing now. @dstogov, could you please take a look when you have a chance?

…ead init

The ZTS per-thread ini refresh runs on_modify at ZEND_INI_STAGE_STARTUP to
populate the new thread's globals; skip the accel_startup_ok guard there so
it is not treated as a post-startup change.
@dkkoma
dkkoma force-pushed the fix-gh-22216-opcache-memcons-zts branch from 57bacf8 to a5080ed Compare August 16, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant