logo-opclabs-new

Professional OPC Development Tools and Services

opc logo

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.

  • New: QuickOPC now also supports OPC UA Alarms&Conditions.

QuickOPC Price List

Read More

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("http://opcua.demo-this.com:51211/UA/SampleServer", 
      "nsu=http://test.org/UA/Data/;i=10853");

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

Tips and Tricks