Hello. Here is an modified patch for PHP command-line interface. It adds option -D which forces php to chdir to the script directory.
diff -ruN php5-200308051930.orig/sapi/cli/php_cli.c php5-200308051930/sapi/cli/php_cli.c --- php5-200308051930.orig/sapi/cli/php_cli.c 2003-08-01 17:08:26.000000000 +0000 +++ php5-200308051930/sapi/cli/php_cli.c 2003-08-06 00:33:49.000000000 +0000 @@ -97,6 +97,7 @@ {'B', 1, "process-begin"}, {'C', 0, "no-chdir"}, /* for compatibility with CGI (do not chdir to script directory) */ {'c', 1, "php-ini"}, + {'D', 0, "chdir"}, {'d', 1, "define"}, {'E', 1, "process-end"}, {'e', 0, "profile-info"}, @@ -362,6 +363,7 @@ " -a Run interactively\n" " -c <path>|<file> Look for php.ini file in this directory\n" " -n No php.ini file will be used\n" + " -D Go to script directory\n" " -d foo[=bar] Define INI entry foo with value 'bar'\n" " -e Generate extended information for debugger/profiler\n" " -f <file> Parse <file>.\n" @@ -527,6 +529,8 @@ const char *param_error=NULL; int scan_input = 0; int hide_argv = 0; + int do_chdir = 0; + char *new_cwd; /* end of temporary locals */ #ifdef ZTS zend_compiler_globals *compiler_globals; @@ -687,6 +691,9 @@ case 'C': /* don't chdir to the script directory */ /* This is default so NOP */ break; + case 'D': /* chdir to the script directory */ + do_chdir = 1; + break; case 'd': /* define ini entries on command line */ define_command_line_ini_entry(optarg); break; @@ -902,6 +909,12 @@ zend_llist_destroy(&global_vars); PG(during_request_startup) = 0; + if (do_chdir && strcmp(file_handle.filename, "-")) { + new_cwd = strdup(file_handle.filename); + php_dirname(new_cwd, strlen(new_cwd)); + chdir(new_cwd); + free(new_cwd); + } switch (behavior) { case PHP_MODE_STANDARD: if (strcmp(file_handle.filename, "-")) { -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php