ID: 27412 User updated by: chris at seismo dot usbr dot gov dot spamfree Reported By: chris at seismo dot usbr dot gov dot spamfree Status: Assigned Bug Type: iPlanet related Operating System: IRIX 6.5 PHP Version: 4CVS, 5CVS (2004-02-27) Assigned To: thetaphi New Comment:
Further testing indicates that Netscape/iPlanet Enterprise Server uses the sproc/sprocsp model of threading on IRIX, at least for versions 3 and 4. According to the sproc man page "The sproc model of threading is incompatible with POSIX threads." A problem with sproc threads is that they can quickly use up all available process memory unless the per-process stack size is kept *small* enough. With PHP NSAPI, this will result in a segment violation (SIGSEGV), with a "not enough memory to lock stack" syslog error. So with PHP, one may need to limit the per-process stacksize when starting ns-httpd. For example: (limit stacksize 8m && $NSES_PATH/start) Previous Comments: ------------------------------------------------------------------------ [2004-03-09 05:25:58] [EMAIL PROTECTED] Can you send me the patch as Unified Diff to my email? ------------------------------------------------------------------------ [2004-03-08 20:11:44] chris at seismo dot usbr dot gov dot spamfree TSRM.c needed a few more minor changes to have complete NSAPI support. Without these, you eventually get SIGSEGV. The point of these changes is to permit choice of using NSAPI thread API, thus avoiding dependency on native threads (and resulting problems on some platforms). Here are the complete context diffs for php-4.3.5RC3: *** 91,96 **** --- 91,98 ---- #if defined(PTHREADS) /* Thread local storage */ static pthread_key_t tls_key; + #elif defined(NSAPI) + static int tls_key; #elif defined(TSRM_ST) static int tls_key; #elif defined(TSRM_WIN32) *************** *** 106,111 **** --- 108,115 ---- pth_init(); #elif defined(PTHREADS) pthread_key_create( &tls_key, 0 ); + #elif defined(NSAPI) + tls_key = systhread_newkey(); #elif defined(TSRM_ST) st_init(); st_key_create(&tls_key, 0); *************** *** 186,191 **** --- 190,197 ---- #elif defined(PTHREADS) pthread_setspecific(tls_key, 0); pthread_key_delete(tls_key); + #elif defined(NSAPI) + /* systhread_setdata(tls_key, 0); /* as bogus as pthread_setspecific(key,0) */ #elif defined(TSRM_WIN32) TlsFree(tls_key); #endif *************** *** 261,266 **** --- 267,274 ---- #if defined(PTHREADS) /* Set thread local storage to this new thread resources structure */ pthread_setspecific(tls_key, (void *) *thread_resources_ptr); + #elif defined(NSAPI) + systhread_setdata(tls_key, (void *) *thread_resources_ptr); #elif defined(TSRM_ST) st_thread_setspecific(tls_key, (void *) *thread_resources_ptr); #elif defined(TSRM_WIN32) *************** *** 302,307 **** --- 310,317 ---- * and our hashtable lookup. */ thread_resources = pthread_getspecific(tls_key); + #elif defined(NSAPI) + thread_resources = systhread_getdata(tls_key); #elif defined(TSRM_ST) thread_resources = st_thread_getspecific(tls_key); #elif defined(TSRM_WIN32) *************** *** 390,395 **** --- 400,407 ---- } #if defined(PTHREADS) pthread_setspecific(tls_key, 0); + #elif defined(NSAPI) + /* systhread_setdata(tls_key, 0); /* as bogus as pthread_setspecific(key,0) */ #elif defined(TSRM_WIN32) TlsSetValue(tls_key, 0); #endif *************** *** 524,530 **** #elif defined(PTHREADS) return pthread_mutex_lock(mutexp); #elif defined(NSAPI) ! return crit_enter(mutexp); #elif defined(PI3WEB) return PISync_lock(mutexp); #elif defined(TSRM_ST) --- 536,543 ---- #elif defined(PTHREADS) return pthread_mutex_lock(mutexp); #elif defined(NSAPI) ! crit_enter(mutexp); /* returns void */ ! return 0; #elif defined(PI3WEB) return PISync_lock(mutexp); #elif defined(TSRM_ST) *************** *** 551,557 **** #elif defined(PTHREADS) return pthread_mutex_unlock(mutexp); #elif defined(NSAPI) ! return crit_exit(mutexp); #elif defined(PI3WEB) return PISync_unlock(mutexp); #elif defined(TSRM_ST) --- 564,571 ---- #elif defined(PTHREADS) return pthread_mutex_unlock(mutexp); #elif defined(NSAPI) ! crit_exit(mutexp); /* returns void */ ! return 0; #elif defined(PI3WEB) return PISync_unlock(mutexp); #elif defined(TSRM_ST) For completeness, here are the context diffs for TSRM.h: *** 45,50 **** --- 45,52 ---- # include <pth.h> #elif defined(PTHREADS) # include <pthread.h> + #elif defined(NSAPI) + # include <nsapi.h> #elif defined(TSRM_ST) # include <st.h> #elif defined(BETHREADS) As discribed above, configure still needs hacking to turn off pthreads and get the proper defines. If I get a chance, I'll make the m4 changes to do that cleanly, and post those as well. ------------------------------------------------------------------------ [2004-02-27 19:09:07] chris at seismo dot usbr dot gov dot spamfree Thanks for taking a look. Given Netscape's definitive statement that NSAPI does not support pthreads, it may be more luck than anything else if it appears to be working for some. More likely it's implementation dependent, as indicated by the bug reports where people just gave up on PHP - even with Solaris. The biggest risk could be not knowing what other problems pthreads are causing. A more robust approach might be to always use NES/iPlanet's thread API (NSAPI) - no matter what version or platform. Since NSAPI seems to already include a common thread API, does PHP really need to worry with those details? Both NSAPI and XP_UNIX should be defined in CFLAGS because TSRM.h includes nsapi.h. Just defining XP_UNIX or NSAPI in nsapi.c won't work. ------------------------------------------------------------------------ [2004-02-27 10:27:31] [EMAIL PROTECTED] I will go through your changes. The problem is that even in iPlanet4 / NES3 the pthreads work correct on the most used platforms (e.g. Solaris). So changing could be a risk and needs a lot of testing. But for PHP5 we should think about it. One question: Why not update to a "supported" version of the NSAPI (e.g. SunONE webserver 6.1 ?). NES3 is really old... One comment: explicit defining of XP_UNIX is not needed in the current version because this is done by a #define in the sapi/nsapi/nsapi.c file - the problem is only if you change the TSRM to include nsapi.h here - you also need this there. But for that you can copy the code to TSRM. ------------------------------------------------------------------------ [2004-02-27 08:43:12] chris at seismo dot usbr dot gov dot spamfree Corrections/typos: (1) NSAPI.h should read TSRM.h (2) Fix for TSRM.c should read #elif defined(NSAPI) crit_enter(mutexp); /* returns void */ return 0; #elif defined(PI3WEB) (3) Also need to disable test for $pthreads_working in configure NSAPI section: enable_experimental_zts=yes # if test "$pthreads_working" != "yes"; then # { echo "configure: error: ZTS currently requires working POSIX threads. We were unable to verify that your system supports Pthreads." 1>&2; exit 1; } # fi (4) sapi/nsapi/config.m4 is semi-busted even without the NSAIP thread/pthread bug: change if test -d $PHP_NSAPI/include ; then NSAPI_INCLUDE=$PHP_NSAPI/include AC_MSG_RESULT(Netscape-Enterprise 3.x style) AC_CHECK_HEADERS([$NSAPI_INCLUDE/nsapi.h]) fi to if test -d $PHP_NSAPI/include ; then NSAPI_INCLUDE=$PHP_NSAPI/include AC_MSG_RESULT(Netscape-Enterprise 3.x style) AC_CHECK_HEADERS([$NSAPI_INCLUDE/nsapi.h]) NSAPI_INCLUDE="$NSAPI_INC_DIR -I$NSAPI_INCLUDE" dnl basic bug fix AC_DEFINE(NSAPI,1,[ ]) dnl partial pthread fix AC_DEFINE(XP_UNIX,1,[ ]) dnl partial pthread fix fi In configure, these lines would be change fi if test -d $PHP_NSAPI/plugins/include ; then test -n "$NSAPI_INCLUDE" && NSAPI_INC_DIR="-I$NSAPI_INCLUDE" to CFLAGS="$CFLAGS -DNSAPI -DXP_UNIX" NSAPI_INCLUDE="$NSAPI_INC_DIR -I$NSAPI_INCLUDE" fi if test -d $PHP_NSAPI/plugins/include ; then test -n "$NSAPI_INCLUDE" && NSAPI_INC_DIR="-I$NSAPI_INCLUDE" sapi/nsapi/config.m4 needs a more general fix though, including modifying the macro PHP_BUILD_THREAD_SAFE for NS3 and 4 to require enable_experimental_zts=yes, but not pthread. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/27412 -- Edit this bug report at http://bugs.php.net/?id=27412&edit=1