PHP WMI查询超时

问题描述 投票:0回答:1

我正在扫描子网以收集有关网络上资产的WMI信息。但是,如果一台机器卡在POST中或存在一些未知问题,它将冻结脚本,并且永远不会继续使用下一台机器。问题是,是否可以在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
php wmi
1个回答
1
投票

简短的回答,不-因为它是一个COM对象,而不是PHP对象,并且没有直接控制它的工具。

更长远的推测性答案,您可以尝试通过注册表特别是TcpInitialRtt来调整TCP parameters,尽管除非您在非常可靠且不拥挤的网络上运行,否则似乎并没有太大的改变范围。而且您可能会破坏机器上运行的其他内容。

© www.soinside.com 2019 - 2024. All rights reserved.