|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-01-29 21:57 UTC] maroszek at gmx dot net
Description: ------------ PHP 7.1.1 + This patch: https://gist.github.com/weltling/e0922914dca8c8ee1886 (See bug #71129) You need the patch. Otherwise you won't get to the shutdown part because it will crash during parallel execution. Build the test app and run it. It will crash on module shutdown. Hints: It will NOT crash if no script is started It will NOT crash if scripts are started from main It will NOT crash on MacOS/Linux Test script: --------------- #include <stdio.h> #include <iostream> #include <thread> #include <list> #define PHP_WIN32 1 #define ZEND_WIN32 1 #define ZTS 1 #define ZEND_DEBUG 0 //#define _USE_32BIT_TIME_T 0 #include <main/php.h> #include <main/SAPI.h> #include <main/php_main.h> #include <main/php_variables.h> #include <main/php_ini.h> #include <zend_ini.h> #if defined(PHP_WIN32) && defined(ZTS) ZEND_TSRMLS_CACHE_DEFINE(); #endif zend_module_entry ips_module_entry = { STANDARD_MODULE_HEADER, "XYZ", NULL, NULL, NULL, NULL, NULL, NULL, NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; static size_t php_embed_read_post(char *str, size_t str_length) { return 0; } static char* php_embed_read_cookies() { return NULL; } static size_t php_embed_ub_write(const char *str, size_t str_length) { std::cout << str; return str_length; } static void php_embed_flush(void *server_context) { // } static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context) { // } static void php_embed_log_message(char *message, int type) { fprintf(stderr, "%s\n", message); } static void php_embed_register_variables(zval *track_vars_array) { //zval ipsValue; //ZVAL_STRING(&ipsValue, "Blaaaaaaaa"); //php_register_variable_ex("Blubber", &ipsValue, track_vars_array); } static int php_embed_startup(sapi_module_struct *sapi_module) { if (php_module_startup(sapi_module, NULL, 0) == FAILURE) { return FAILURE; } return SUCCESS; } sapi_module_struct php_embed_module = { "XYZ", /* name */ "PHP for XYZ", /* pretty name */ php_embed_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ NULL, /* activate */ NULL, /* deactivate */ php_embed_ub_write, /* unbuffered write */ php_embed_flush, /* flush */ NULL, /* get uid */ NULL, /* getenv */ php_error, /* error handler */ NULL, /* header handler */ NULL, /* send headers handler */ php_embed_send_header, /* send header handler */ php_embed_read_post, /* read POST data */ php_embed_read_cookies, /* read Cookies */ php_embed_register_variables, /* register server variables */ php_embed_log_message, /* Log message */ NULL, /* Get request time */ NULL, /* Child terminate */ STANDARD_SAPI_MODULE_PROPERTIES }; unsigned __stdcall phpThread(void* params) { ts_resource(0); #if defined(PHP_WIN32) && defined(ZTS) ZEND_TSRMLS_CACHE_UPDATE(); #endif for (int i = 0; i < 10; i++) { zend_file_handle file_handle; file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = "date.php"; file_handle.handle.fp = NULL; file_handle.opened_path = NULL; file_handle.free_filename = 0; if (php_request_startup(TSRMLS_C) == FAILURE) { //std::cout << "ERR" << std::endl; php_request_shutdown(NULL); continue; } if (php_execute_script(&file_handle TSRMLS_CC) == FAILURE) break; //std::cout << "RUN" << std::endl; php_request_shutdown(NULL); } std::cout << "FINISHED" << std::endl; return 0; } int main(int argc, const char * argv[]) { tsrm_startup(128, 1, 0, NULL); zend_signal_startup(); sapi_startup(&php_embed_module); php_embed_module.ini_entries = "date.timezone=Europe/Berlin\n\0"; if (php_embed_module.startup(&php_embed_module) == FAILURE) { throw std::runtime_error("Could not start PHP!"); } std::list<std::shared_ptr<std::thread>> threads; for (int i = 0; i < 1; i++) { threads.push_back(std::make_shared<std::thread>([]{phpThread(NULL);})); } for(auto& thread: threads) { thread->join(); } php_embed_module.shutdown(&php_embed_module); sapi_shutdown(); tsrm_shutdown(); return 0; } Expected result: ---------------- Nice and clean shutdown Actual result: -------------- php7ts.dll!zend_llist_destroy(_zend_llist * l) php7ts.dll!php_shutdown_ticks() php7ts.dll!ts_free_id(int id) php7ts.dll!php_module_shutdown() php7ts.dll!php_module_shutdown_wrapper(_sapi_module_struct * sapi_globals) PHPCrash.exe!main(int argc, const char * * argv) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 13 21:00:01 2025 UTC |
Thanks for fixing the issue! For Linux it works as is - for Windows i had to make a small change to my custom SAPI. I was using this line, which was causing crashes on Windows. tsrm_startup(128, 1, 0, NULL); After changing it to the way the embed library does it the crashes went away. tsrm_startup(1, 1, 0, NULL); What i don't understand, is how a parameter that is named expected_threads can causes crashes, after setting it to a sane value. Here is my reworked crash example which uses the embed library: https://gist.github.com/paresy/3cbd4c6a469511ac7479aa0e7c42fea7 I will try my best to post next reports based on the official embed implementation! :)