Jump to content

Recommended Posts

Posted

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?

 

Posted
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.

 

  • Like 2
Posted

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 ?

Posted

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).

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...