prosportal
prosportal

Reputation: 109

PHP WMI Query timeout

I am scanning a subnet to gather WMI information on assets on the network. However, if a machine is stuck in POST or has some unknown issue, it will freeze the script and never move on to the next machine. Question is, is there a way to set a timeout on PHP COM WbemScripting.SWbemLocator?

    $host = 10.1.1.5; //Host is online, but may be hung trying to shutdown

    //Check if host is online
    if(@$fp = fsockopen($host,135,$errCode,$errStr,0.1))
    {
        //Create new connection
        $WbemLocator = new COM ("WbemScripting.SWbemLocator");

        //Connect to remote workstation
        $WbemServices = $WbemLocator->ConnectServer($host, 'root\\cimv2',$user,$password);  
        $WbemServices->Security_->ImpersonationLevel = 3;

        //Basic WMI query
        $system = $WbemServices->execQuery("Select * from Win32_ComputerSystem");   

        foreach($pcsystem AS $n){

            $hostname = $n->Name; //Hostname

        }

        //Process all data ->Insert into DB
    }
//Move on to next machine. In this case, the script will never move on

Upvotes: 0

Views: 183

Answers (1)

symcbean
symcbean

Reputation: 48387

Short answer, no - because it's a COM object, not a PHP object, and there's no facility to control this directly.

Longer, speculative answer, you could try tweaking the TCP parameters via the registry notably TcpInitialRtt although there doesn't seem to be a lot of scope for changing the behaviour unless you are running on a very reliable and uncongested network. And you'll probably break other things running on the machine.

Upvotes: 1

Related Questions