php调用rrdtool图片没有显示

zjkw123 2009-06-16 10:11:53
<?php
$fd=popen("/usr/local/rrdtool/bin/rrdtool - ","w");
if(!$fd){
print("cannot open");
return;
}
$start=1245000000;
$end=1245500000;
$t="--start $start --end $end";
$def="DEF:t1=\"sample.rrd\":item1:AVERAGE DEF:t2=sample.rrd:item2:AVERAGE";
$line="LINE1:t1#00ff00 LINE2:t2#330088";
$command="$t $def $line\r\n";

$i=0;
while(1){
if(fwrite($fd," graph - ".$command)==false){
fclose($fd);
$fd=popen("/usr/local/rrdtool/bin/rrdtool - ","w");
if($i>4){
print("cannot write");
return;
}else{
$i++;
}
continue;
}else{
fflush($fd);

break;
}
}
if(isset($fd)){
print fpassthru($fd);
exit;
}
?>
图片出不来???
第二行改成$fd=popen("/usr/local/rrdtool/bin/rrdtool - >1.png","w");可以生成1.png图片
...全文
563 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinesetyq 2009-06-20
  • 打赏
  • 举报
回复
学习!
tankinc 2009-06-20
  • 打赏
  • 举报
回复
最近在看cacti的源代码
zjkw123 2009-06-20
  • 打赏
  • 举报
回复
调用RRDTOOL生成流量图片,一般都是rrdtool graph 1.png ...... 可以生成1.png,但我不想生成其他文件而是直接显示,参考了一下CACTI里的rrd.php,他的函数:
function rrdtool_execute($command_line, $log_to_stdout, $output_flag, $rrd_struc = array(), $logopt = "WEBLOG") {
global $config;

if (!is_numeric($output_flag)) {
$output_flag = RRDTOOL_OUTPUT_STDOUT;
}

/* WIN32: before sending this command off to rrdtool, get rid
of all of the '\' characters. Unix does not care; win32 does.
Also make sure to replace all of the fancy \'s at the end of the line,
but make sure not to get rid of the "\n"'s that are supposed to be
in there (text format) */
$command_line = str_replace("\\\n", " ", $command_line);

/* output information to the log file if appropriate */
if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG) {
cacti_log("CACTI2RRD: " . read_config_option("path_rrdtool") . " $command_line", $log_to_stdout, $logopt);
}

/* if we want to see the error output from rrdtool; make sure to specify this */
if (($output_flag == RRDTOOL_OUTPUT_STDERR) && (!isset($rrd_struc["fd"]) || (sizeof($rrd_struc["fd"]) == 0))) {
$command_line .= " 2>&1";
}

/* use popen to eliminate the zombie issue */
if ($config["cacti_server_os"] == "unix") {
/* an empty $rrd_struc array means no fp is available */
if (!isset($rrd_struc["fd"]) || (sizeof($rrd_struc["fd"]) == 0)) {
session_write_close();
$fp = popen(read_config_option("path_rrdtool") . escape_command(" $command_line"), "r");
}else{
$i = 0;

while (1) {
if (fwrite(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ), escape_command(" $command_line") . "\r\n") == false) {
cacti_log("ERROR: Detected RRDtool Crash attempting to perform write");

/* close the invalid pipe */
rrd_close($rrd_struc);

/* open a new rrdtool process */
$rrd_struc = rrd_init();

if ($i > 4) {
cacti_log("FATAL: RRDtool Restart Attempts Exceeded. Giving up on command.");

break;
}else{
$i++;
}

continue;
}else{
fflush(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ));

break;
}
}
}
}elseif ($config["cacti_server_os"] == "win32") {
/* an empty $rrd_struc array means no fp is available */
if (!isset($rrd_struc["fd"]) || (sizeof($rrd_struc["fd"]) == 0)) {
session_write_close();
$fp = popen(read_config_option("path_rrdtool") . escape_command(" $command_line"), "rb");
}else{
$i = 0;

while (1) {
if (fwrite(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ), escape_command(" $command_line") . "\r\n") == false) {
cacti_log("ERROR: Detected RRDtool Crash attempting to perform write");

/* close the invalid pipe */
rrd_close($rrd_struc);

/* open a new rrdtool process */
$rrd_struc = rrd_init();

if ($i > 4) {
cacti_log("FATAL: RRDtool Restart Attempts Exceeded. Giving up on command.");

break;
}else{
$i++;
}

continue;
}else{
fflush(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ));

break;
}
}
}
}

switch ($output_flag) {
case RRDTOOL_OUTPUT_NULL:
return; break;
case RRDTOOL_OUTPUT_STDOUT:
if (isset($fp)) {
$line = "";
while (!feof($fp)) {
$line .= fgets($fp, 4096);
}

return $line;
}

break;
case RRDTOOL_OUTPUT_STDERR:
if (isset($fp)) {
$output = fgets($fp, 1000000);

if (substr($output, 1, 3) == "PNG") {
return "OK";
}

if (substr($output, 0, 5) == "GIF87") {
return "OK";
}

print $output;
}

break;
case RRDTOOL_OUTPUT_GRAPH_DATA:
if (isset($fp)) {
return fpassthru($fp);
}

break;
}
}
phpboy 2009-06-18
  • 打赏
  • 举报
回复

while(1){
if(fwrite($fd," graph - ".$command)==false){
fclose($fd);
$fd=popen("/usr/local/rrdtool/bin/rrdtool - ","w");
if($i>4){
print("cannot write");
return;
}else{
$i++;
}


没看明白这写的什么东西,支持一下,顶上去
zjkw123 2009-06-16
  • 打赏
  • 举报
回复
弄错了,不是print fpassthru($fd);而是fpassthru($fd);
而且print fpassthru($fd);输出0,
不知道该怎么写,高手?????

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧