1. Go to this page and download the library: Download php-opcua/laravel-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/ */
use PhpOpcua\Client\Types\BuiltinType;
$client = Opcua::connect();
$client->write('ns=2;i=1001', 42, BuiltinType::Int32);
// Or let the client auto-detect the type
$client->write('ns=2;i=1001', 42);
$client->disconnect();
// EventServiceProvider
use PhpOpcua\Client\Event\DataChangeReceived;
Event::listen(DataChangeReceived::class, function (DataChangeReceived $e) {
DB::table('sensor_readings')->insert([
'value' => $e->dataValue->getValue(),
'client_handle' => $e->clientHandle,
]);
});
use Illuminate\Support\Facades\Event;
use PhpOpcua\Client\Event\ClientConnected;
use PhpOpcua\Client\Event\NodeValueWriteFailed;
use PhpOpcua\Client\Event\AlarmActivated;
// Log connections
Event::listen(ClientConnected::class, function ($e) {
logger()->info("Connected to {$e->endpointUrl}");
});
// Track write failures
Event::listen(NodeValueWriteFailed::class, function ($e) {
logger()->warning("Write failed on {$e->nodeId}: 0x" . dechex($e->statusCode));
});
// Alert operators on alarms
Event::listen(AlarmActivated::class, function ($e) {
Notification::send(
User::role('operator')->get(),
new AlarmTriggered($e->sourceName, $e->severity, $e->message),
);
});
use PhpOpcua\Client\Testing\MockClient;
use PhpOpcua\Client\Types\DataValue;
$mock = MockClient::create()
->onRead('i=2259', fn() => DataValue::ofInt32(0));
// Inject into OpcuaManager via DI or reflection
$value = $mock->read('i=2259');
echo $value->getValue(); // 0
echo $mock->callCount('read'); // 1
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.