@@ -194,9 +194,6 @@ PHP_MSHUTDOWN_FUNCTION(appserver)
194194
195195PHP_MINIT_FUNCTION (appserver )
196196{
197- zval * const_value , * const_name ;
198- char * sapiname ;
199-
200197 REGISTER_INI_ENTRIES ();
201198
202199 /* init globals */
@@ -207,8 +204,27 @@ PHP_MINIT_FUNCTION(appserver)
207204
208205PHP_RINIT_FUNCTION (appserver )
209206{
210- char * ptr ;
211- char * str ;
207+ char * ptr , * str , * sapiconst = APPSERVER_CONSTANT_PHP_SAPI ;
208+ zend_constant * defined ;
209+ zval * new_phpsapi ;
210+ char * new_phpsapi_name = APPSERVER_SAPI_NAME ;
211+
212+ /* create zval for new sapi string */
213+ MAKE_STD_ZVAL (new_phpsapi );
214+ ZVAL_STRING (new_phpsapi , new_phpsapi_name , 1 );
215+
216+ /* check if PHP_SAPI const can be found to overwrite cli sapi name to appserver */
217+ if (zend_hash_find (EG (zend_constants ), sapiconst , strlen (sapiconst )+ 1 , (void * * ) & defined ) == SUCCESS ) {
218+ /* create new constant with new php sapi name */
219+ zend_constant c ;
220+ c .value = * new_phpsapi ;
221+ c .flags = PHP_USER_CONSTANT ;
222+ c .name = zend_strndup (& sapiconst , strlen (sapiconst ));
223+ c .name_len = strlen (sapiconst ) + 1 ;
224+ c .module_number = 0 ;
225+ /* update PHP_SAPI constant in hash table */
226+ zend_hash_update (EG (zend_constants ), sapiconst , strlen (sapiconst )+ 1 , (void * )& c , sizeof (zend_constant ), (void * * )& c );
227+ }
212228
213229 /* remove functions given in ini setting */
214230 ptr = strtok (INI_STR ("appserver.remove_constants" ), "," );
@@ -219,7 +235,6 @@ PHP_RINIT_FUNCTION(appserver)
219235 ptr = strtok (NULL , "," );
220236 }
221237
222-
223238 /* remove functions given in ini setting */
224239 ptr = strtok (INI_STR ("appserver.remove_functions" ), "," );
225240 while (ptr != NULL ) {
0 commit comments