Hello.
Here is a patch for the command-line version of PHP which makes it chdir()
to the
script directory just like the web version of PHP does. It also implements
the -C
option which has been a NOOP up to now.

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-05
23:39:38.000000000 +0000
@@ -360,6 +360,7 @@
                    "       %s [options] -- [args...]\n"
                    "\n"
                                "  -a               Run interactively\n"
+                               "  -C               Don't chdir to the
script directory\n"
                                "  -c <path>|<file> Look for php.ini file in
this directory\n"
                                "  -n               No php.ini file will be
used\n"
                                "  -d foo[=bar]     Define INI entry foo
with value 'bar'\n"
@@ -527,6 +528,8 @@
        const char *param_error=NULL;
        int scan_input = 0;
        int hide_argv = 0;
+       int no_chdir=0;
+       char *new_cwd;
 /* end of temporary locals */
 #ifdef ZTS
        zend_compiler_globals *compiler_globals;
@@ -685,7 +688,7 @@
                                break;

                        case 'C': /* don't chdir to the script directory */
-                               /* This is default so NOP */
+                               no_chdir = 1;
                                break;
                        case 'd': /* define ini entries on command line */
                                define_command_line_ini_entry(optarg);
@@ -902,6 +905,12 @@
                zend_llist_destroy(&global_vars);

                PG(during_request_startup) = 0;
+               if (!no_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

Reply via email to