chrizz Posted June 30, 2019 Share Posted June 30, 2019 I was wondering which logic is behind the httpUrl method when multiple hosts are availble? My config says $config->httpHosts = array('api.local', 'www.api.local', '10.0.1.10'); $page->httpUrl returns always api.local. In the current setup 10.0.1.10 would be appreciated. Is there any logic behind this or is just the first host taken for the httpUrl() call? Checking the code brings up this comment Quote * This is set automatically by ProcessWire at runtime, consisting of one of the values * specified in $config->httpHosts. However, if you set a value for this, it will override * ProcessWire's runtime value. But: How is this runtime valued defined when I use this method in a hook? Link to comment Share on other sites More sharing options...
Robin S Posted June 30, 2019 Share Posted June 30, 2019 2 hours ago, chrizz said: Is there any logic behind this or is just the first host taken for the httpUrl() call? See ProcessWire::getHttpHost(). If PW cannot match a host in your $config->httpHosts array from PHP's predefined $_SERVER variable then it gives you the first item from $config->httpHosts. 2 Link to comment Share on other sites More sharing options...
chrizz Posted July 1, 2019 Author Share Posted July 1, 2019 thanks for bringing this up. To me this means: a cronjob will always use the first defined host, as there's no $_SERVER variable available, aye? Unless for sure the cronjob is called via http (e.g. "curl https:host.../") Thanks for your feedback - helps a lot ? Link to comment Share on other sites More sharing options...
dragan Posted July 1, 2019 Share Posted July 1, 2019 For such scenarios, you can always add as many custom $config items as you need. Or pass parameters to the cron-script. Or maybe even use gethostname(), as suggested here (untested). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now