1. Go to this page and download the library: Download techdock/opcua library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
techdock / opcua example snippets
use TechDock\OpcUa\Client\ClientBuilder;
use TechDock\OpcUa\Core\Types\NodeId;
// Connect to server
$client = ClientBuilder::create()
->endpoint('opc.tcp://localhost:4840')
->withAnonymousAuth()
->build();
// Read a value
$serverTime = $client->session->read([NodeId::numeric(0, 2258)])[0];
echo "Server time: {$serverTime->value}\n";
// Browse nodes
$objectsFolder = NodeId::numeric(0, 85);
$references = $client->browser->browse($objectsFolder);
foreach ($references as $ref) {
echo "- {$ref->displayName->text}\n";
}
// Clean up
$client->disconnect();