Do .htaccess php_value settings affect scripts run

2019-06-22 14:25发布

I'm investigating the best place to set my error logging options, and it seems the most reliable place would be in .htaccess in the script subdirectory. But this particular script is run via cron, and therefore via command line.

Do php_value settings made in .htaccess affect scripts that are not run through the web server?

3条回答
手持菜刀,她持情操
2楼-- · 2019-06-22 15:04

.htaccess is used only by Apache. So the answer is NO.

查看更多
干净又极端
3楼-- · 2019-06-22 15:09

Are you referring to php's error logging settings? Or some custom error logging configuration specific to your cron job?

Either way, you have a few options.

Option 1. Edit your php command in your cron job to include the arguments you want to pass to the script and retrieve them with $argv & $argc. See http://us2.php.net/manual/en/features.commandline.php#86616

Option 2. If you are changing php's error logging options -only- for scripts ran from the cli, you can make those changes in your php-cli.ini (or whatever it might be named on your system)

Option 3. If you don't want to alter php-cli.ini file, you can copy your php-cli.ini somewhere else, make the necessary changes and then alter your php command in your cron job to use the -c /path/to/new/php-cli.ini.

Option 4. Set environment variable(s) on your server and retrieve with $_SERVER['ENV_VAR_NAME_HERE']

I'd be tempted to go with Option 1, unless there are multiple scripts using the same arguments.

Good luck.

查看更多
甜甜的少女心
4楼-- · 2019-06-22 15:19

No, .htaccess files are only read from the PHP httpd module.

查看更多
登录 后发表回答