I am reading some values like Operating system version, CPU Load, Memory Size... with WMI from a remote PC. At top of my PHP script I am building a connection to the remote PC and then query informations. When I open my page the first time it takes 15-20 seconds for the first WMI connection and after that i get the required values. When I reload the page after 3-5 seconds the values are updated immediatly (after 1-2 seconds). But when I keep the page open for a while and reload after 1 Minute, I see that the connection is lost and connecting once more, so it takes again 20 seconds that i get the updated values. It seems so that the WMI connection is closed after a while. How can I keep the WMI connection open, as long as the php page is open, or perhaps define a session time like 5 Minutes ?
<?php
// Connection to WMI ****************
$strComputer = "10.92.114.85";
$objSWbemLocator = new COM ("WbemScripting.SWbemLocator");
$objSWbemServices = $objSWbemLocator->ConnectServer($strComputer, "root\cimv2", "user", "password");
$objSWbemServices->Security_->ImpersonationLevel = 3;
$obj = $objSWbemServices;
$Processor = $obj->ExecQuery("Select * from Win32_Processor");
$PhysicalMemory = $obj->ExecQuery("Select * from Win32_PhysicalMemory");
// WMI Processor Informations
foreach ( $Processor as $wmi_Processor )
{
$CPUName = $wmi_Processor->Name;
$CPU3264bit = $wmi_Processor->AddressWidth;
$CPUSpeed = $wmi_Processor->MaxClockSpeed;
$CPUCores = $wmi_Processor->NumberOfCores;
}
// showing values on screen
?>