在Windows中为CACTI使用cURL和PHP

在Windows中为CACTI使用cURL和PHP,php,curl,cacti,Php,Curl,Cacti,最近的任务是通过CACTI监控外部网页响应/加载时间。我发现了一些使用cURL的PHP脚本(pageload-agent.PHP和class.pageload.PHP)。在他们要求将其从LINUX传输到Windows2012R2服务器之前,一切都正常工作。我很难修改脚本以适应windows。已经安装了PHP和cURL,并且都可以正常工作。以下是从AskabHP获取的脚本 class.pageload.php <?php class PageLoad { var $siteURL = "";

最近的任务是通过CACTI监控外部网页响应/加载时间。我发现了一些使用cURL的PHP脚本(pageload-agent.PHP和class.pageload.PHP)。在他们要求将其从LINUX传输到Windows2012R2服务器之前,一切都正常工作。我很难修改脚本以适应windows。已经安装了PHP和cURL,并且都可以正常工作。以下是从AskabHP获取的脚本

class.pageload.php

<?php
class PageLoad {
var $siteURL = "";
var $pageInfo = "";
/*
* sets the URLs to check for loadtime into an array $siteURLs
*/
function setURL($url) {
    if (!empty($url)) {
        $this->siteURL = $url;
        return true;
    }
    return false;
}

/*
* extract the header information of the url 
*/
function doPageLoad() {
    $u = $this->siteURL;
    if(function_exists('curl_init') && !empty($u)) {
        $ch = curl_init($u);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_NOBODY, false);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, false); 
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
        $pageBody = curl_exec($ch);
        $this->pageInfo = curl_getinfo($ch);
        curl_close ($ch);
        return true;
    }
    return false;
}

/*
* compile the page load statistics only
*/
function getPageLoadStats() {
    $info = $this->pageInfo;

    //stats from info
    $s['dest_url'] = $info['url'];
    $s['content_type'] = $info['content_type'];
    $s['http_code'] = $info['http_code'];
    $s['total_time'] = $info['total_time'];
    $s['size_download'] = $info['size_download'];
    $s['speed_download'] = $info['speed_download'];
    $s['redirect_count'] = $info['redirect_count'];
    $s['namelookup_time'] = $info['namelookup_time'];
    $s['connect_time'] = $info['connect_time'];
    $s['pretransfer_time'] = $info['pretransfer_time'];
    $s['starttransfer_time'] = $info['starttransfer_time'];
    return $s;
}   
}
?>

pageload-agent.php

#! /usr/bin/php -q
<?php
//include the class
include_once 'class.pageload.php';
// read in an argument - must make sure there's an argument to use
if ($argc==2) {
//read in the arg.
$url_argv = $argv[1];
if (!eregi('^http://', $url_argv)) {
    $url_argv = "http://$url_argv";
}
// check that the arg is not empty
if ($url_argv!="") {

    //initiate the results array
    $results = array();

    //initiate the class
    $lt = new PageLoad();

    //set the page to check the loadtime
    $lt->setURL($url_argv);

    //load the page
    if ($lt->doPageLoad()) {
        //load the page stats into the results array
        $results = $lt->getPageLoadStats();
    } else {
        //do nothing
        print "";
    }

    //print out the results
    if (is_array($results)) {
        //expecting only one record as we only passed in 1 page.
        $output = $results;

        print "dns:".$output['namelookup_time'];
        print " con:".$output['connect_time'];
        print " pre:".$output['pretransfer_time'];
        print " str:".$output['starttransfer_time'];
        print " ttl:".$output['total_time'];
        print " sze:".$output['size_download'];
        print " spd:".$output['speed_download'];
    } else {
        //do nothing
        print "";
    }
}
} else {
//do nothing
print "";
}
?>
#/usr/bin/php-q

你能更具体地谈谈遇到的问题吗?嗨,杰拉德。基本上我得到的信息是0。我可以手动运行cURL并获取一些信息,但运行脚本会得到0个结果。你能解释一下这两个脚本是否都可以在Windows环境下运行吗?
eregi
已被弃用,因此这可能是一个问题,具体取决于你使用的php版本。我安装了PHP5.6.14