Forum
PHP Parse error in config.production.php during CRON
We recently moved a site from one domain to another. For the new domain, we installed Perch Runway from scratch and then imported. The site is running fine but we have an issue with the scheduled task CRON job.
The original site was set up a while ago and contains just one config file (config.php) with config.local.php being empty. The scheduled tasks ran perfectly.
The new site has a config.php file that starts with these lines ...
switch($_SERVER['SERVER_NAME']) {
case 'www.xxxx.org.uk':
include(__DIR__.'/config.www-xxxx-org-uk.php');
break;
default:
include('config.production.php');
break;
}
The file called config.www-xxxx-org-uk.php has the normal 'define' statements I would expect to see. The file called config.production.php is empty (save for an opening <?php statement)
If you run the scheduled task using http it works fine. If you run the scheduled task with CRON, we see the error of ... PHP Parse error: syntax error, unexpected end of file in /home/xxxxxx/public_html/perch/config/config.production.php on line 1.
The CRON job command line is as follows ...
/opt/cpanel/ea-php71/root/usr/bin/php /home/xxxxxx/public_html/perch/core/scheduled/run.php xxxxxxxxxx
I am guessing that this statement is causing the 'default' case to be selected in the config.php file. And, because the config.production.php contains no statements we are seeing this error. Has anyone else come across this and, if so, what's the solution they used?
Thanks, Graham
Is your CLI version of PHP running PHP 5.4 or greater?
The site and CLI are both running PHP 7.1.16.
I've tried editing config.production.php and added the closing ?> to match the opening <?php. There are no other parameters in config.production.php.
When /opt/cpanel/ea-php71/root/usr/bin/php /home/xxxxxx/public_html/perch/core/scheduled/run.php xxxxxxxxxx is run it produces a message of 'You must set a secret. See https://docs.grabaperch.com/docs/scheduled-tasks/ for configuration instructions.'.
So, I then I replicated the contents of config.www-xxxx-org-uk.php into config.production.php. The CRON job now works.
The result is I've got around the issue, but I wonder if others are hitting the same problem? Or is it just me?
Hello Graham,
If you don't intend on having different config files for different environments, you can replace the whole
switch
statement with the content of yourconfig.www-xxxx-org-uk.php
.The
switch
statement is used in the main config file so you can use different configurations based on the environment you are on (dev, staging or production). It uses$_SERVER['SERVER_NAME']
to determine which environment you are on.When the cron task runs if
$_SERVER['SERVER_NAME']
is not available (or is set to a value other than those you are testing against in theswitch
statement), theswitch
statement will use thedefault
statement.So:
switch
statement (add all your configs in the main file).default
statement should include your production config (you can call the file anything you want) for cases like these$_SERVER['SERVER_NAME']
is available (and is set to the value you expect) when you run the cron task.Thanks Hussein
You've confirmed what I planned to do. Basically revert to a single config.php file. I'm fairly sure that $_SERVER['SERVER_NAME'] will not have a value when run in a CRON job, but will check with my hosting company anyway.
My main reason for the posting was to point out the issue that other people may face - the CRON job (running the command in CLI) is defaulting to an empty config file in the config files/structure that's set up in a new install of Runway. If someone else has this issue, maybe they'll search the forum and find this posting.
Regards, Graham
Just to close this off ... I've now reverted to a single config.php file, without the 'switch'. Running the scheduling command line in CLI (with CRON) works fine.