So I’m sure all you web server gurus out there already know about this and how to fix it, but I couldn’t find any posts about it so I thought I would leave one for any other web-site newbies trying to use Yii to create a SOAP server.
[size="5"]A description of the symptoms[/size]
You create a SOAP server according to the Yii tutorial on how to do so. It works fine from anywhere inside your local sub-net, but when you try to call the service from outside your sub-net (i.e. accross the internet using a registered domain name), it fails with one of the following:
DTD are not supported by SOAP
Error Fetching http headers
Upon further inspection (using SOAP option ‘trace’ set to 1 and then the SoapClient::__getLastResponse() function) you see that the problem is with SoapServer constructor in line 155 of CWebService.php.
<body> <h1>PHP Error</h1> <h3>Description</h3> <p class="message"> SoapServer::SoapServer(http://www.website.com/index.php?r=stock/quote'): failed to open stream: Connection timed out</p> <h3>Source File</h3> <p> /var/www/yii/framework/web/services/CWebService.php(155)</p> ...
Line 155 of CWebService.php is:
As you can see, it tries to construct the SoapServer with the WSDL URL that was passed in by the client. In the case of a client outside the server’s subnet, this will be a domain name that resolves to an external ip address which is not generally accessable by the server itself. So when the server tries to use it to create a PHP SoapServer object, it times out trying to find that external ip address.
The easiest is to edit your server’s hosts file to route the external domain name to the local host.
127.0.0.1 website.com www.website.com
You could also set up a local DNS server that re-routes the external domain name to whatever server you want within your subnet.
Like I mentioned, this is probably obvious to those of you who are web pros, but it wasn’t to me and it is possible that there are others out there who might run into it as they are starting out.
I hope it helps someone!