106
106
#define PHP_MODE_REFLECTION_CLASS 9
107
107
#define PHP_MODE_REFLECTION_EXTENSION 10
108
108
109
+ #define HARDCODED_INI \
110
+ "html_errors=0\n" \
111
+ "register_argc_argv=1\n" \
112
+ "implicit_flush=1\n" \
113
+ "output_buffering=0\n" \
114
+ "max_execution_time=0\n" \
115
+ "max_input_time=-1\n"
116
+
117
+
109
118
static char * php_optarg = NULL ;
110
119
static int php_optind = 1 ;
111
120
#if (HAVE_LIBREADLINE || HAVE_LIBEDIT ) && !defined(COMPILE_DL_READLINE )
@@ -342,10 +351,6 @@ static int php_cli_startup(sapi_module_struct *sapi_module)
342
351
zend_hash_update(configuration_hash, name, sizeof(name), tmp, sizeof(zval), (void**)&entry);\
343
352
Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry))
344
353
345
- /* hard coded ini settings must be set in main() */
346
- #define INI_HARDCODED (name ,value )\
347
- zend_alter_ini_entry(name, sizeof(name), value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
348
-
349
354
static void sapi_cli_ini_defaults (HashTable * configuration_hash )
350
355
{
351
356
zval * tmp , * entry ;
@@ -451,29 +456,6 @@ static void php_cli_usage(char *argv0)
451
456
}
452
457
/* }}} */
453
458
454
- static void define_command_line_ini_entry (char * arg TSRMLS_DC )
455
- {
456
- char * name , * value ;
457
-
458
- name = arg ;
459
- value = strchr (arg , '=' );
460
- if (value ) {
461
- * value = 0 ;
462
- value ++ ;
463
- } else {
464
- value = "1" ;
465
- }
466
-
467
- if (!strcasecmp (name , "extension" )) { /* load function module */
468
- zval extension , zval ;
469
- ZVAL_STRING (& extension , value , 0 );
470
- php_dl (& extension , MODULE_PERSISTENT , & zval , 1 TSRMLS_CC );
471
- } else {
472
- zend_alter_ini_entry (name , strlen (name )+ 1 , value , strlen (value ), PHP_INI_SYSTEM , PHP_INI_STAGE_ACTIVATE );
473
- }
474
- }
475
-
476
-
477
459
static php_stream * s_in_process = NULL ;
478
460
479
461
static void cli_register_file_handles (TSRMLS_D )
@@ -602,6 +584,7 @@ int main(int argc, char *argv[])
602
584
int argc = __argc ;
603
585
char * * argv = __argv ;
604
586
#endif
587
+ int ini_entries_len = 0 ;
605
588
606
589
#if defined(PHP_WIN32 ) && defined(_DEBUG ) && defined(PHP_WIN32_DEBUG_HEAP )
607
590
{
@@ -646,6 +629,10 @@ int main(int argc, char *argv[])
646
629
setmode (_fileno (stderr ), O_BINARY ); /* make the stdio mode be binary */
647
630
#endif
648
631
632
+ ini_entries_len = strlen (HARDCODED_INI );
633
+ cli_sapi_module .ini_entries = malloc (ini_entries_len + 2 );
634
+ memcpy (cli_sapi_module .ini_entries , HARDCODED_INI , ini_entries_len + 1 );
635
+ cli_sapi_module .ini_entries [ini_entries_len + 1 ] = 0 ;
649
636
650
637
while ((c = php_getopt (argc , argv , OPTIONS , & php_optarg , & php_optind , 0 ))!= -1 ) {
651
638
switch (c ) {
@@ -655,6 +642,23 @@ int main(int argc, char *argv[])
655
642
case 'n' :
656
643
cli_sapi_module .php_ini_ignore = 1 ;
657
644
break ;
645
+ case 'd' : {
646
+ /* define ini entries on command line */
647
+ int len = strlen (php_optarg );
648
+
649
+ if (strchr (php_optarg , '=' )) {
650
+ cli_sapi_module .ini_entries = realloc (cli_sapi_module .ini_entries , ini_entries_len + len + sizeof ("\n\0" ));
651
+ memcpy (cli_sapi_module .ini_entries + ini_entries_len , php_optarg , len );
652
+ memcpy (cli_sapi_module .ini_entries + ini_entries_len + len , "\n\0" , sizeof ("\n\0" ));
653
+ ini_entries_len += len + sizeof ("\n\0" ) - 2 ;
654
+ } else {
655
+ cli_sapi_module .ini_entries = realloc (cli_sapi_module .ini_entries , ini_entries_len + len + sizeof ("=1\n\0" ));
656
+ memcpy (cli_sapi_module .ini_entries + ini_entries_len , php_optarg , len );
657
+ memcpy (cli_sapi_module .ini_entries + ini_entries_len + len , "=1\n\0" , sizeof ("=1\n\0" ));
658
+ ini_entries_len += len + sizeof ("=1\n\0" ) - 2 ;
659
+ }
660
+ break ;
661
+ }
658
662
}
659
663
}
660
664
php_optind = orig_optind ;
@@ -683,7 +687,6 @@ int main(int argc, char *argv[])
683
687
module_started = 1 ;
684
688
685
689
zend_first_try {
686
- zend_uv .html_errors = 0 ; /* tell the engine we're in non-html mode */
687
690
CG (in_compilation ) = 0 ; /* not initialized but needed for several options */
688
691
EG (uninitialized_zval_ptr ) = NULL ;
689
692
@@ -693,21 +696,9 @@ int main(int argc, char *argv[])
693
696
goto out_err ;
694
697
}
695
698
696
- /* here is the place for hard coded defaults which cannot be overwritten in the ini file */
697
- INI_HARDCODED ("register_argc_argv" , "1" );
698
- INI_HARDCODED ("html_errors" , "0" );
699
- INI_HARDCODED ("implicit_flush" , "1" );
700
- INI_HARDCODED ("output_buffering" , "0" );
701
- INI_HARDCODED ("max_execution_time" , "0" );
702
- INI_HARDCODED ("max_input_time" , "-1" );
703
-
704
699
while ((c = php_getopt (argc , argv , OPTIONS , & php_optarg , & php_optind , 0 )) != -1 ) {
705
700
switch (c ) {
706
701
707
- case 'd' : /* define ini entries on command line */
708
- define_command_line_ini_entry (php_optarg TSRMLS_CC ) ;
709
- break ;
710
-
711
702
case 'h' : /* help & quit */
712
703
case '?' :
713
704
if (php_request_startup (TSRMLS_C )== FAILURE ) {
@@ -1260,6 +1251,10 @@ int main(int argc, char *argv[])
1260
1251
if (cli_sapi_module .php_ini_path_override ) {
1261
1252
free (cli_sapi_module .php_ini_path_override );
1262
1253
}
1254
+ if (cli_sapi_module .ini_entries ) {
1255
+ free (cli_sapi_module .ini_entries );
1256
+ }
1257
+
1263
1258
if (module_started ) {
1264
1259
php_module_shutdown (TSRMLS_C );
1265
1260
}
0 commit comments