WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   Hilfe bei einem PHP-Scrip bitte! (http://www.wcm.at/forum/showthread.php?t=175316)

Alter 03.10.2005 21:14

Hilfe bei einem PHP-Scrip bitte!
 
Ich beginne eben erst PHP zu lernen, deshalb bin ich auf Hilfe angewiesen:
Das PHP-Script phpboinc, das die client_state.xml des Boinc-Clients ausliest und als HTML-Seite ausgibt, mag mich nicht so recht, wie es scheint. Standardmässig ist die Variable $dir nicht definiert, aber was ich dort auch eintrage, auch wenn ich nix eintrage, ich bekomme immer nur: "Could not locate BOINC directory at:" zurückgemeldet (je nachdem, ob ich ein Verzeichnis angebe oder sonstwas, steht nach dem Doppelpunkt der jeweils eingetragene Wert und das war es.
Was mache ich falsch?

Der Autor des Scripts hat nirgendwo eine Kontaktmail hinterlassen, der will seine Ruhe haben. Ich möchte das aber trotzdem zum Laufen bringen, weil man damit theoretisch ja schön auch andere XML Files parsen und andere Ergebnisse ausgeben könnte, wenn man das Script nur ein wenig umstrickt.

Hier findet man das Script: http://one.zer0x.net/~rjsilvers/scripts/php/phpboinc/

Das File, das ausgelesen werden soll liegt in c:/Programme/BOINC/client_state.xml

Alter 03.10.2005 21:16

Das Script hat folgenden Code:
PHP-Code:

<HTML>
<HEAD>
<TITLE>phpBOINC v1.0 by Richard Silvers</TITLE>
</HEAD>
<BODY>
<?
class BOINClass {
  var 
$cpuName;
  var 
$cpuModel;
  var 
$cpuOSName;
  var 
$cpuOSVersion;
  var 
$cpuProcs;
  var 
$cpuVendor;
  var 
$cpuFLOPS;
  var 
$cpuIOPS;

  var 
$perOn;
  var 
$perConnected;
  var 
$perActive;

  var 
$bwUp;
  var 
$bwDown;

  var 
$projectName;
  var 
$userName;
  var 
$teamName;

  var 
$creditTotal;
  var 
$creditAverage;

}


function 
startElement($parser$name$attrs) {
  global 
$curTag;
  
$curTag .= "^$name";
}

function 
endElement($parser$name) {
  global 
$curTag;
  
$caret_pos strrpos($curTag'^');
  
$curTag substr($curTag0$caret_pos);
}

function 
characterData($parser$data) { 
  global 
$curTag
  global 
$BOINC;

  
$cpuNameKey "^CLIENT_STATE^HOST_INFO^DOMAIN_NAME";
  
$cpuModelKey "^CLIENT_STATE^HOST_INFO^P_MODEL";
  
$cpuOSNameKey "^CLIENT_STATE^HOST_INFO^OS_NAME";
  
$cpuOSVersionKey "^CLIENT_STATE^HOST_INFO^OS_VERSION";
  
$cpuProcsKey "^CLIENT_STATE^HOST_INFO^P_NCPUS";
  
$cpuVendorKey "^CLIENT_STATE^HOST_INFO^P_VENDOR";
  
$cpuFLOPSKey "^CLIENT_STATE^HOST_INFO^P_FPOPS";
  
$cpuIOPSKey "^CLIENT_STATE^HOST_INFO^P_IOPS";

  
$perOnKey "^CLIENT_STATE^TIME_STATS^ON_FRAC";
  
$perConnectedKey "^CLIENT_STATE^TIME_STATS^CONNECTED_FRAC";
  
$perActiveKey "^CLIENT_STATE^TIME_STATS^ACTIVE_FRAC";

  
$bwUpKey "^CLIENT_STATE^NET_STATS^BWUP";
  
$bwDownKey "^CLIENT_STATE^NET_STATS^BWDOWN";

  
$projectNameKey "^CLIENT_STATE^PROJECT^PROJECT_NAME";
  
$userNameKey "^CLIENT_STATE^PROJECT^USER_NAME";
  
$teamNameKey "^CLIENT_STATE^PROJECT^TEAM_NAME";

  
$creditTotalKey "^CLIENT_STATE^PROJECT^USER_TOTAL_CREDIT";
  
$creditAverageKey "^CLIENT_STATE^PROJECT^USER_EXPAVG_CREDIT";


  switch (
$curTag) {
    case 
$cpuNameKey:
      
$BOINC->cpuName $data;
      break;
    case 
$cpuModelKey:
      
$BOINC->cpuModel $data;
      break;
    case 
$cpuOSNameKey:
      
$BOINC->cpuOSName $data;
      break;
    case 
$cpuOSVersionKey:
      
$BOINC->cpuOSVersion $data;
      break;
    case 
$cpuProcsKey:
      
$BOINC->cpuProcs $data;
      break;
    case 
$cpuVendorKey:
      
$BOINC->cpuVendor $data;
      break;
    case 
$cpuFLOPSKey:
      
$BOINC->cpuFLOPS $data;
      break;
    case 
$cpuIOPSKey:
      
$BOINC->cpuIOPS $data;
      break;

    case 
$perOnKey:
      
$BOINC->perOn $data;
      break;
    case 
$perConnectedKey:
      
$BOINC->perConnected $data;
      break;
    case 
$perActiveKey:
      
$BOINC->perActive $data;
      break;

    case 
$bwUpKey:
      
$BOINC->bwUp $data;
      break;
    case 
$bwDownKey:
      
$BOINC->bwDown $data;
      break;

    case 
$projectNameKey:
      
$BOINC->projectName $data;
      break;
    case 
$userNameKey:
      
$BOINC->userName $data;
      break;
    case 
$teamNameKey:
      
$BOINC->teamName "A";
      break;

    case 
$creditTotalKey:
      
$BOINC->creditTotal $data;
      break;
    case 
$creditAverageKey:
      
$BOINC->creditAverage $data;
      break;

  }


}

global 
$BOINC;

$BIONC = new BOINClass();
$dir "";
$file "client_state";
$xml_parser xml_parser_create();

xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");

if (!(
$fp fopen($dir $file,"r"))) {
  die (
"Could not locate BOINC directory at: " $dir);
}

while (
$data fread($fp4096)) {
  if (!
xml_parse($xml_parser$datafeof($fp))) {
    die(
sprintf("XML parse error: %s at line %d"
        
xml_error_string(xml_get_error_code($xml_parser)), 
        
xml_get_current_line_number($xml_parser)));
  }
}
xml_parser_free($xml_parser);

echo 
"BOINC Statistics:

"
;
echo 
"Computer Name: " $BOINC->cpuName "
"
;
echo 
"CPU Vendor: " $BOINC->cpuVendor "
"
;
echo 
"CPU Model: " $BOINC->cpuModel "
"
;
echo 
"Number Of Processors: " $BOINC->cpuProcs "
"
;
echo 
"OS: " $BOINC->cpuOSName " " $BOINC->cpuOSVersion "
"
;
printf("Floating Point Speed: %0.2f million ops/sec
"
, ($BOINC->cpuFLOPS 1000000));
printf("Integer Speed: %0.2f million ops/sec

"
, ($BOINC->cpuIOPS 1000000));

echo 
"Percent On: " . ($BOINC->perOn 100) . "%
"
;
echo 
"Percent Connected: " . ($BOINC->perConnected 100) . "%
"
;
echo 
"Percent Active: " . ($BOINC->perActive 100) . "%

"
;

printf("Bandwidth (UP): %0.1f KB/sec
"
, ($BOINC->bwUp 1024));
printf("Bandwidth (DOWN): %0.1f KB/sec

"
, ($BOINC->bwDown 1024));

echo 
"Project: " $BOINC->projectName "
"
;
echo 
"User: " $BOINC->userName "

"
;

echo 
"Total Credits: " $BOINC->creditTotal "
"
;
echo 
"Average Credits: " $BOINC->creditAverage "
"
;
?>
</BODY>
</HTML>


Alter 03.10.2005 21:20

/************************************************** ******
* *
* phpBOINC v1.0 *
* (C) Copyright 2005 Richard Silvers *
* *
* This is a stripped down version of my personal *
* BOINC script. It contains all the necessary code *
* to run, but ONLY the necessary code. Towards the *
* bottom of the file there is an example that shows *
* how to access the data. There is virtually no *
* unnecessary HTML or site-specific code, making it *
* easier to tailor to your particular website. All *
* you have to do is point the script to the *
* client_state.xml file and it will take care of the *
* rest. *
* *
* Note: XML parsing MUST be enabled on the PHP server *
* *
************************************************** ******/

Das steht auch noch drin, aber irgendwas mache ich wohl kervehrt.

T.dot 03.10.2005 22:34

Das Skript versucht bei diesem Code:
Code:

if (!($fp = fopen($dir . $file,"r"))) {
  die ("Could not locate BOINC directory at: " . $dir);
}

eine Datei zu öffnen, dessen Dateinamen sich aus $dir und $file zusammensetzt:

Code:

$dir = "";
$file = "client_state";

Also wird versucht im gleichen Verzeichniss wie die .php Datei liegt die Datei "client_state" zu öffnen. Wenn diese nicht vorhanden ist, kommt der Fehler "Could not locate BOINC directory at". Wenn du ein Directory angibst musst du dies entweder absolut oder relativ zum Verzeichniss in dem das PHP File liegt tun. Am Ende muss ein / stehen.
Achja, der Webserver muss natürlich Zugriffsrechte auf die Datei haben, wenns also ausserhalb vom Webdir liegt wirds mit einfacher Pfadangabe nicht funktionieren. Kopier zum Testen am einfachsten die Datei ins gleiche Verzeichniss wie das Script.

Ich hab den Code nicht genauer gelesen (der ist meiner Meinung nach auch nicht besonders toll), aber dies hier kommt mir auch seltsam vor:

Code:

global $BOINC;

$BIONC = new BOINClass();

wobei $BIONC nicht weiter verwendet wird...

mfg T.

Alter 03.10.2005 23:44

Jetzt hab ich es endlich raus:

Das Script geht davon aus, dass sowohl boinc.php als auch Client_state.xml in einem Verzeichnis liegen, das "BOINC" heißt.

Ist das nicht doof? :rolleyes:

Danke für deine Antwort!


Alle Zeitangaben in WEZ +2. Es ist jetzt 20:53 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag