| eyebrow | Docs · Getting started | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| lede | Build an HttpsTransport, wire it into ClientBuilder, and connect to an opc.https:// endpoint. Three steps. | |||||||||||||||
| see_also |
|
|||||||||||||||
| prev |
|
|||||||||||||||
| next |
|
-
Build the transport
use PhpOpcua\Client\ExtTransportHttps\HttpsTransport; use PhpOpcua\Client\ExtTransportHttps\Encoding\BinaryHttpsEncoding; use PhpOpcua\Client\ExtTransportHttps\Http\CurlHttpClient; $transport = new HttpsTransport( httpClient: new CurlHttpClient(verifyTls: true, caBundle: '/etc/ssl/certs/ca-bundle.crt'), encoding: new BinaryHttpsEncoding(), endpointUrl: 'opc.https://server.example:443/UA/', timeoutSeconds: 30.0, );
Both
opc.https://and plainhttps://URLs are accepted asendpointUrl; the constructor normalises tohttps://internally. -
Plug it into
ClientBuilderuse PhpOpcua\Client\ClientBuilder; use PhpOpcua\Client\Security\SecurityMode; use PhpOpcua\Client\Security\SecurityPolicy; $client = (new ClientBuilder()) ->setSecurityPolicy(SecurityPolicy::None) ->setSecurityMode(SecurityMode::None) ->setTransport($transport) ->setUserCredentials('admin', 'admin123') ->connect('opc.https://server.example:443/UA/');
The
Client::connect()flow detects the external secure channel viaHttpsTransport::isSecureChannelExternal() === trueand skips theOpenSecureChannelhandshake. TLS is the secure channel. Username/Password identity is used here because UA-.NETStandard filters Anonymous out of HTTPS endpoints when mTLS is off. -
Use the client as usual
$value = $client->read('i=2259'); echo $value->getValue(); // 0 = Running $refs = $client->browse('i=85'); foreach ($refs as $ref) { echo $ref->getBrowseName()->getName() . PHP_EOL; } $client->disconnect();
Every OPC UA service call becomes one HTTPS POST under the hood.
$transport = new HttpsTransport(
httpClient: new CurlHttpClient(
verifyTls: true,
caBundle: '/etc/ssl/certs/ca-bundle.crt',
clientCertPath: '/certs/client.pem',
clientKeyPath: '/certs/client.key',
clientKeyPassword: getenv('CLIENT_KEY_PASS') ?: null,
),
encoding: new BinaryHttpsEncoding(),
endpointUrl: 'opc.https://server.example:443/UA/',
);setClientCertificate() on the builder is for OPC UA application-level
certificates; mTLS cert / key for the TLS layer go on CurlHttpClient.