note 38000 added to function.include
| From: | david dot gaia dot kano at dartmouth dot edu | Date: | Thu, 04 Dec 2003 06:13:29 +0000 |
| Subject: | note 38000 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61378@lists.php.net to get a copy of this message | ||
I just discovered a "gotcha" for the behavior of include when using the command line
version of php.
I copied all the included files needed for a new version of a program into a temporary directory, so
I could run them "off to the side" before they were ready for release into the live area.
One of the files with a new version (call it common.inc.php for this example) normally lives in one
of the directories in the include path. But I did not want to put the new version there yet! So I
copied common.inc.php into my temporary directory along with the others, figuring that the
interpreter would find it there before it found it in the include directory, because my include path
has a . at the beginning. When I tested it, everything was fine.
But then I setup a cron job to run the script automatically every day. In the crontab I placed the
full path of the script. But when it ran, it included the old version of my common.inc.php file out
of the include directory. Interestingly, the other include files that only existed in the temporary
directory were included fine.
Evidently AFTER the include path is searched, the directory in which the main script lives is
searched as well. So my temporary installation almost worked fine, except for the lack of the small
change I had made in the common file introduced a bug.
To make it work I use a shell script to start my php script. It contains a cd command into the
temporary directory, then starts the php script.
So "current directory" (the . in the include path) for a command line script is really the
current directory you are in when executing the script. Whereas it means the directory in which the
script lives when executing under apache.
I hope this helps save someone else the hours it took me to figure out my problem!
David
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38000
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38000&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38000&report=yes
Search -- http://master.php.net/manage/user-notes.php