Disable certificate verification in PHP SoapClient

Disable certificate verification in PHP SoapClient

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Disable Certificate Verification in PHP SoapClient

When a new application lands on a server without an established DNS entry or an SSL certificate, connecting to it via SoapClient hits an immediate wall. The default behavior of the underlying SOAP stack is strict: it enforces TLS protocol requirements and validates the server's certificate against your local trust store. If the certificate is missing, self-signed, or hasn't been signed by a trusted Certificate Authority (CA), the connection attempt fails immediately with a SSL_ERROR_RX_RECORD_TOO_LONG or a specific SoapClient fault indicating an SSL error.

In a development environment, this rigidity often feels like unnecessary friction. You might simply want to bypass the check to verify that your service logic works before you jump through the hoops of generating a Certificate Signing Request (CSR), configuring DNS records, and waiting for CA approval. While ignoring certificate validation is a known security anti-pattern in production—it opens the door to Man-in-the-Middle attacks where an attacker could intercept sensitive SOAP payloads—it is a pragmatic necessity for local debugging and early-stage integration testing.

To make SoapClient ignore these checks, you need to instantiate the client with a custom StreamContext. The core mechanism involves creating a stream context where the SSL verification flag is explicitly set to false. This tells the underlying OpenSSL library within PHP to skip the certificate chain validation while still establishing an encrypted connection.

Here is how you implement this in modern PHP (7.4 and later):

$context = stream_context_create([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ]
]);

$client = new SoapClient('https://localhost:8080/MyService', [
    'stream_context' => $context
]);

// Now the client can connect without a valid certificate
$result = $client->getFunctionName();

The configuration array passed to stream_context_create is where the magic happens. Setting 'verify_peer' => false disables the check of the certificate against your local bundle (usually located at /etc/ssl/certs/ca-certificates.crt). Setting 'verify_peer_name' => false relaxes the hostname verification, which prevents errors if the server presents a certificate for example.com but you are connecting to localhost.

It is crucial to distinguish between disabling SSL entirely and disabling verification. You should never attempt to bypass HTTPS by using HTTP (http://) in your URL; doing so disables encryption completely, sending all SOAP data in plaintext. The goal here is strictly to disable validation of the certificate identity, not to remove the encryption layer.

There are specific pitfalls to be aware of when implementing this solution. First, ensure you are passing the context as an associative array under the key 'stream_context' within the SoapClient constructor options. Passing it as a positional argument or omitting the wrapper array often results in the context being ignored, leaving you with the same SSL errors. Second, remember that this configuration is scoped to the specific instance of the SoapClient. If you are using dependency injection or a framework service container, you must ensure the custom context is applied at every instantiation point.

If your application runs on a shared hosting environment where modifying global PHP configurations is impossible, this approach remains one of the few viable paths for testing without installing local SSL certificates like selfsigned or reconfiguring the server's trust store. However, once the DNS entry and a valid certificate are in place, you must remove these flags from your production code immediately to restore security posture.

Our network