Professional OPC
Development Tools


Integrating PHP and OPC

Are you having difficulties incorporating the OPC data into your PHP solution? Need to create an OPC PHP program quickly and in quality? If so, QuickOPC comes to the rescue.

QuickOPC is a set of components that simplify the task of integrating OPC client functionality into custom applications. Reading a value from OPC Data Access or OPC Unified Architecture (OPC UA) server, or writing a data value can be achieved in just one or two lines of code!

QuickOPC is a radically new approach to access OPC data. Traditionally, OPC programming required complicated code, no matter whether you use OPC custom or automation interfaces. OPC Server objects must be instantiated, OPC Group objects must be created and manipulated, OPC Items must be added and managed properly, and subscriptions must be established and maintained. Too many lines of error-prone code must be written to achieve a simple goal – reading or writing a value. QuickOPC saves you all that hassle.

  • QuickOPC also supports OPC UA Alarms&Conditions.

QuickOPC Price List

Read More

Useful links: PHP Examples / PHP in nowledge Base / PHP examples GitHub repository

OPC PHP Code Samples

QuickOPC is unbelievably easy to use - here is a PHP example which reads and displays OPC data from a common OPC Data Access server:


   // Create EasyOPC-DA component
   $Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
// Read item value and display it print $Client->ReadItemValue("", "OPCLabs.KitServer", "Demo.Single");

Do you think it can be any simpler? But the simplicity is not the only advantage; the component is also very powerful. Using complex heuristic algorithms to optimize itself on the fly, it provides the most efficient, fastest access to the OPC data.

Application-side subscriptions are possible, too. The PHP example below shows how subscribe to changes of a single item and display the value of the item with each change.

   class DEasyDAClientEvents {
      function ItemChanged($varSender, $varE)
         print $varE->Vtq->ToString();
         print "\n";

   $Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
   $Events = new DEasyDAClientEvents();
   com_event_sink($Client, $Events, "DEasyDAClientEvents");

   $Client->SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Random", 1000);

   print "Processing item changed events for 1 minute...\n";
   for ($time = 0; $time < 60; $time++) com_message_pump(1000);

It is also easy to communicate with an OPC Unified Architecture (OPC-UA) server:

   // Instantiate the client object 
   $Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient");

   // Perform the operation 
   $value = $Client->ReadValue("opc.tcp://", 

   // Display results 
   printf("Value: %s\n", $value);


The PubSub variety of OPC UA (as opposed to client-server) uses message-oriented middleware to deliver the data. QuickOPC supports it as well, as shown in the example below.

class SubscriberEvents {
    function DataSetMessage($Sender, $E)
        printf("%s\n", $E);

$SubscribeDataSetArguments = new COM("OpcLabs.EasyOpc.UA.PubSub.OperationModel.EasyUASubscribeDataSetArguments");
$ConnectionDescriptor = $SubscribeDataSetArguments->DataSetSubscriptionDescriptor->ConnectionDescriptor;
$ConnectionDescriptor->ResourceAddress->ResourceDescriptor->UrlString = "opc.udp://";

$Subscriber = new COM("OpcLabs.EasyOpc.UA.PubSub.EasyUASubscriber");
$SubscriberEvents = new SubscriberEvents();
com_event_sink($Subscriber, $SubscriberEvents, "DEasyUASubscriberEvents");


Tips and Tricks

  • Example using ReadMultipleItems and PHP: search online forums
  • Using the Event Pull Mechanism, you can enjoy the benefits of OPC subscriptions, while not having to set up event handlers (which can be problematic e.g. in context of short-lived Web request handlers).



Footnote & required disclosure: QuickOPC (including its Options) is a software development kit (SDK) for development of OPC clients and subscribers. Installing QuickOPC or its Options does not change system settings.