comment post failed
| From: | Marijn Wijbenga | Date: | Thu, 30 Nov 2006 17:15:12 +0000 |
| Subject: | comment post failed | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-33416@lists.php.net to get a copy of this message | ||
Hi Webmaster,
I tried to post a comment at this page: http://nl3.php.net/manual/en/function.win32-ps-list-procs.php
but it says my IP is listed in some sort of blacklist. I don't know how but i am not the only one using this IP.
For the sake of the community, could you place the comment ? Comment is below the line.
Thanks,
Marijn
p.s.
Please do not include my email adres for spam reasons
-----------------------------
I tried to figuire out how to get the total processor load of the server and after 3 days of searching/testing i got this code. Hope someone will need this as well, and saving his time to find out for him/her self.
<?php
$processorCount = 2;
$filename = "proclist.ser";
// create new file if it does not exists
if (!file_exists($filename))
{
$file = fopen($filename, "w");
fwrite($file, serialize(array()));
fclose($file);
}
// load prev processlist from file
$file = fopen($filename, "r");
$processList = unserialize(fread($file, filesize($filename)));
fclose($file);
// get current processlist
$list = @win32_ps_list_procs();
$processCurrent = array();
$totalKernel = 0; $totalUser = 0;// process all processes for ($i = 0; $i < count($list); $i++) { // what is the key index of the array? $key = "pid_" . $list[$i]["pid"]; // fill in new list $processCurrent[$key] = array();
$processCurrent[$key]["pid"] = $list[$i]["pid"]; $processCurrent[$key]["exe"] = $list[$i]["exe"];$processCurrent[$key]["created"] = $list[$i]["tms"]["created"]; $processCurrent[$key]["kernel"] = $list[$i]["tms"]["kernel"];
$processCurrent[$key]["user"] = $list[$i]["tms"]["user"];// calculate diff $diffCreated = $processCurrent[$key]["created"] - ((isSet($processList[$key])) ? $processList[$key]["created"] : 0); $diffKernel = $processCurrent[$key]["kernel"] - ((isSet($processList[$key])) ? $processList[$key]["kernel"] : 0);
$diffUser = $processCurrent[$key]["user"] - ((isSet($processList[$key])) ? $processList[$key]["user"] : 0);// set proc load $processCurrent[$key]["load_kernel"] = (100 / $processorCount) * $diffKernel / $diffCreated;
$processCurrent[$key]["load_user"] = (100 / $processorCount) * $diffUser / $diffCreated;// addup for total load $totalKernel += $processCurrent[$key]["load_kernel"]; $totalUser += $processCurrent[$key]["load_user"]; } // write processlist to file $file = fopen($filename, "w"); fwrite($file, serialize($processCurrent)); fclose($file); // dump echo("<table>"); echo("<tr><th>Proc</th><th>user</th><th>kernel</th> <th>total</th></tr>"); // dump total echo("<tr><td>Total CPU load</td><td>" . Round($totalUser, 2) . "</td><td>" . Round($totalKernel, 2) . "</td><td>" . Round($totalUser + $totalKernel, 2) . "</td></tr>"); // dump procs reset($processCurrent); while (list($key, $value) = each($processCurrent)) { echo("<tr><td>" . $value["exe"] . "</td><td>" . Round($value["load_user"], 2) . "</td><td>" . Round($value["load_kernel"], 2) . "</td><td>" . Round($value["load_user"] + $value["load_kernel"], 2) . "</td></tr>"); } // end of dump echo("</table>"); // set refresh to 2 sec echo("<script>window.setTimeout(\"window.location.reload();\", 2000);</script>"); ?> This code uses a file (called 'proclist.ser') to save the data from the previous request, so make sure the webserver has write access. This file is needed as reference, the load will be calculated as average from previous request. At first the code worked fine with the exception that when the load gets high it exceeds 100% and i was wondering how that happens, but after some testing i figuired out that it is so becourse i have 2 processors in my server. That is why i made the $processorCount var. After this the load is very similar to the 'taskmanager'. If someone knows a function to retreive the number of processors that would be a nice addition to this script. Hope this makes some sense :D Gr, Marijn