SOAP PHP fault parsing WSDL: failed to load external entity?
The error SOAP-ERROR: Parsing WSDL: Couldn't load from '...' : failed to load external entity is a specific symptom of how PHP's SOAP extension resolves resources. It indicates that the parser successfully opened the primary file (e.g., login.wsdl) but immediately encountered an XML parsing exception while trying to resolve a reference within that document.
In your specific case, the root cause is not network connectivity or WAMP server configuration; it is the location of the <xsd:schema> declaration inside the WSDL file.
The Hidden External Entity
Look closely at the types section of your login.wsdl:
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Login">
<!-- ... elements defined here ... -->
</xsd:schema>
</types>
The schema is defined directly within the WSDL. However, when the SOAP parser attempts to process this, it often expects a complete, self-contained XML document or specific external entity declarations if the schema references other files. The error message failed to load external entity suggests that the parser is trying to resolve something it cannot find in the current context.
In older versions of PHP (like the 5.3.13 you are using) and certain configurations, the SOAP extension can be overly strict or misconfigured regarding XML entities. If your WSDL relies on implicit external references or if the internal schema is malformed relative to the parser's expectations, it throws this specific fault.
Fixing the WSDL Structure
The most reliable fix is to ensure your WSDL is self-contained and strictly adheres to the SOAP specification without relying on ambiguous external entity loading.
- Verify Schema Self-Containment: Ensure there are no missing
xmlnsdeclarations or that you aren't inadvertently referencing an external.xsdfile via<xs:import>unless that file definitely exists at the URL provided in your project directory. - Check for Character Encoding Issues: The error can sometimes stem from non-standard characters (like smart quotes instead of straight quotes, or hidden BOMs) causing the XML parser to fail when reading entity references. Ensure your
login.wsdlis saved as UTF-8 without BOM.
If you must keep the schema inline (which is standard for simple services), ensure the targetNamespace matches exactly between the WSDL definition and the schema declaration. In your code, you have:
- WSDL
targetNamespace="urn:Login"inside the schema tag. - WSDL definitions
targetNamespace="urn:LoginVal".
While PHP is relatively forgiving, mismatches here can sometimes trigger parsing ambiguities that older parsers interpret as entity loading failures. Ensure the namespace used in <xsd:element> matches the one defined in the WSDL context.
Correcting the Server-Side Logic
Beyond the WSDL structure, there are critical issues in your register.php server script that will prevent the service from functioning even after fixing the parsing error.
Method Signature Mismatch: Your WSDL defines an operation named
loginVerify. However, your PHP function is also namedloginVerify, but the logic inside checks for$_POST["regname"]. In a SOAP context, arguments are passed as distinct parameters (e.g.,$username,$password), not via the$_POSTsuperglobal. You must access the function arguments directly:public function loginVerify($username, $password) { // Do not use $_POST here // Validate $username and $password directly }Database Security: Your current implementation uses
mysql_connectand concatenates user input directly into SQL queries ("insert into users ... values('...')"). This is a severe security vulnerability (SQL Injection) and is also deprecated in modern PHP versions. You should switch to PDO or MySQLi with prepared statements.Function Registration: The line
$server->AddFunction("loginVerify");is incorrect for theSoapServerclass in standard PHP installations. When you define a public method with the same name as the operation (or match the WSDL definition), the SOAP server automatically discovers and registers it. You do not need to manually add the function unless you are using specific legacy extensions or custom namespaces.
Conclusion
The failed to load external entity error is caused by how the PHP SOAP extension interprets your inline schema within the WSDL, likely exacerbated by the older PHP 5.3.13 environment and strict XML parsing rules. Correcting the WSDL to ensure it is strictly self-contained with matching namespaces will resolve the parsing fault. Simultaneously, refactoring register.php to handle SOAP arguments correctly and using secure database practices will make the service functional and safe.
