PHP shebang parameters

Does PHP not honor parameters in the shebang line if passed?

How do you set a custom php.ini file when creating a CLI script?

[code]#!/usr/bin/php -c /etc/customphp56/php.ini

<?php print(date("n")); ?>[/code]

complains about date.timezone not being set. But it is set in /etc/customphp56/php.ini

Hi sparek,

There seems to be a problem when trying to pass arguments to PHP via the shebang. You’d be better off setting the timezone in your main php.ini file.

That’s not really ideal. There are other changes I’d like to make to this customize php.ini file.

In the interim, I’ve changed to calling the script by passing the php CLI binary directly

/usr/bin/php -c /etc/customphp56/php.ini /path/to/file.php

That seems to work.

Just would prefer this to work through the shebang line. Not sure why it’s not. I pulled out many hairs from my head this afternoon trying to figure this out.

Yes, you have to use the command line to do it. There are a couple of ways of getting around this problem:

  1. Set the timezone in the script: http://php.net/manual/en/function.date-default-timezone-set.php
#!/usr/bin/php
<?php
date_default_timezone_set('Europe/London');
print(date("n"));
?>
  1. Have a php script run a php script

###one.php

<?php
exec('/usr/bin/php -c /etc/customphp56/php.ini two.php', $output);
echo $output;
?>

###two.php

<?php
print(date("n"));
?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.