Re: [PHP] include_once changed behavior?
On Tuesday 08 June 2004 03:21, Mattias Thorslund wrote: In order to keep configuration files outside the web root I use: include_once('../config.php'); This used to work also when running php scripts from the command line. Now I have a new server and I get no such file or directory when using this construct from the command line. I have worked around this by doing this: $main_folder = realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/..'); include_once($main_folder . '/config.php'); The original, simpler construct still works when calling the page from a web browser, just not when I run it from the command line. The new server has a more recent version of PHP (4.3.4). I don't have the php version of the old server but it was on RedHat 9 - now I'm on Mandrake 10. What could be the difference that caused this? Possibly: manual Using PHP from the command line -c switch -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* You have many friends and very few living enemies. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include_once changed behavior?
Jason Wong wrote: On Tuesday 08 June 2004 03:21, Mattias Thorslund wrote: In order to keep configuration files outside the web root I use: include_once('../config.php'); This used to work also when running php scripts from the command line. Now I have a new server and I get no such file or directory when using this construct from the command line. I have worked around this by doing this: $main_folder = realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/..'); include_once($main_folder . '/config.php'); The original, simpler construct still works when calling the page from a web browser, just not when I run it from the command line. The new server has a more recent version of PHP (4.3.4). I don't have the php version of the old server but it was on RedHat 9 - now I'm on Mandrake 10. What could be the difference that caused this? Possibly: manual Using PHP from the command line -c switch ...except I don't use the -c switch? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include_once changed behavior?
Mattias Thorslund wrote: Hi, In order to keep configuration files outside the web root I use: include_once('../config.php'); This used to work also when running php scripts from the command line. Now I have a new server and I get no such file or directory when using this construct from the command line. I have worked around this by doing this: $main_folder = realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/..'); include_once($main_folder . '/config.php'); The original, simpler construct still works when calling the page from a web browser, just not when I run it from the command line. The new server has a more recent version of PHP (4.3.4). I don't have the php version of the old server but it was on RedHat 9 - now I'm on Mandrake 10. What could be the difference that caused this? /Mattias cli php uses path relative to your current directory, cgi php uses path relative to the executing script. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include_once changed behavior?
Marek Kilimajer wrote: Mattias Thorslund wrote: Hi, In order to keep configuration files outside the web root I use: include_once('../config.php'); This used to work also when running php scripts from the command line. Now I have a new server and I get no such file or directory when using this construct from the command line. I have worked around this by doing this: $main_folder = realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/..'); include_once($main_folder . '/config.php'); The original, simpler construct still works when calling the page from a web browser, just not when I run it from the command line. The new server has a more recent version of PHP (4.3.4). I don't have the php version of the old server but it was on RedHat 9 - now I'm on Mandrake 10. What could be the difference that caused this? /Mattias cli php uses path relative to your current directory, cgi php uses path relative to the executing script. You can use ini_set('include_path', realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/')); at the beginning of your script as workaround -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include_once changed behavior?
Marek Kilimajer wrote: cli php uses path relative to your current directory, cgi php uses path relative to the executing script. That IS interesting. That would explain why: php /var/www/myproject/util/my-cli-script.php ... will break unless I execute it from that same directory. I used to be able to do that from anywhere, though - that's why I passed the full path to the script. So it's got to be some configuration that's different, or that this behavior has changed. /Mattias -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include_once changed behavior?
On Tuesday 08 June 2004 04:14, Mattias Thorslund wrote: What could be the difference that caused this? As Marek had pointed out the behaviour was changed ... Possibly: manual Using PHP from the command line -c switch ...except I don't use the -c switch? ... IIRC just after the change php-cli had a switch that allowed the old behaviour, apparently this is not documented in the manual anymore so you probably have to use an absolute path. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The whole world is a scab. The point is to pick it constructively. -- Peter Beard */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include_once changed behavior?
Jason Wong wrote: Possibly: manual Using PHP from the command line -c switch From the manual: The CLI SAPI does not change the current directory to the directory of the executed script! Note: The CGI SAPI supports the CLI SAPI behaviour by means of the -C switch when run from the command line. In other words, it's possible to make the CGI version work like the CLI version (using absolute paths only). There seems to be no support for making CLI work like CGI, however. /Mattias -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php