FireFly Media Server › Firefly Media Server Forums › Firefly Media Server › Add-on Software › FireStats – Top 40 php script (now with added charts)
- This topic has 175 replies, 17 voices, and was last updated 15 years, 11 months ago by wwarren.
-
AuthorPosts
-
06/12/2007 at 10:02 PM #14739AnonymousInactive
the problem is solved: on my NSLU2 running SlugOS/BE, with installed apache, the gd.so – extension was missing (ipkg install php-gd and restarting apache needed).. thanks for the hints!
06/12/2007 at 10:10 PM #14740sonichouseParticipant@swissy wrote:
the problem is solved: on my NSLU2 running SlugOS/BE, with installed apache, the gd.so – extension was missing (ipkg install php-gd and restarting apache needed).. thanks for the hints!
Glad to hear it.
I hope you enjoy using it, feel free to suggest any improvements you think could be made.07/12/2007 at 3:41 PM #14741sonichouseParticipantOK folks. google announced a charting API today.
I have changed my code to use this rather than libChart.
All my charts now render sub-second, even on my old 133mhz slug ๐
You can switch between the google method and php by setting the USE_GOOGLE or USE_LIBCHART flags in functions.php.
Enjoy the new much faster 1.07.
/Sonic
07/12/2007 at 6:43 PM #14742masParticipantWow this is indeed a lot faster.
2 sec render time now.
BUT there are 2 issues I could see:
1) The Decades Grafik doesnt work. It doesnt autoscale. If all values are over 100 then you get a chart where all columns are max.
2) More seriously, you use a hardcoded exec to /opt/bin/wget. Most php’s run with exec() disabled as it’s a security hazard. Can you maneuver around using an exec call and do it in php itself? One should defenitly not need to use wget in php, as php has plenty of functions to access images on the web and load em.
3) If google is for whatever reason down, then it simply wont show the grafics. Can you put in a fallback to the standard libchart method if googles api doesnt answer withing 10 secs?
07/12/2007 at 7:43 PM #14743sonichouseParticipant@mas wrote:
Wow this is indeed a lot faster.
2 sec render time now.Their engine is very speedy, I suppose it has to scale to support all the requests they get per minute.
@mas wrote:
BUT there are 2 issues I could see:
1) The Decades Grafik doesnt work. It doesnt autoscale. If all values are over 100 then you get a chart where all columns are max.The API isn’t very clever on scaling, I will see what I can do with this.
@mas wrote:
2) More seriously, you use a hardcoded exec to /opt/bin/wget. Most php’s run with exec() disabled as it’s a security hazard. Can you maneuver around using an exec call and do it in php itself? One should defenitly not need to use wget in php, as php has plenty of functions to access images on the web and load em.
This is my second or third week with php, I will find an alternative approach. I first had the charts render just using the google url, but I need the image copy to reference in the summary page. Now that the speed is ok, I suppose the summary page could always get fresh data – but I don’t like that.
@mas wrote:
3) If google is for whatever reason down, then it simply wont show the grafics. Can you put in a fallback to the standard libchart method if googles api doesnt answer withing 10 secs?
Not sure, worth considering though ๐
07/12/2007 at 8:05 PM #14744masParticipant@sonichouse wrote:
@mas wrote:
2) More seriously, you use a hardcoded exec to /opt/bin/wget. Most php’s run with exec() disabled as it’s a security hazard. Can you maneuver around using an exec call and do it in php itself? One should defenitly not need to use wget in php, as php has plenty of functions to access images on the web and load em.
This is my second or third week with php, I will find an alternative approach. I first had the charts render just using the google url, but I need the image copy to reference in the summary page. Now that the speed is ok, I suppose the summary page could always get fresh data – but I don’t like that.
Yeah I see. NP. I am also no php guru but I can immediately imagine 3 ways to do it inside php.
1) As the code seems to require fopen for URLs enabled anyway we could simply use the copy() call.
That should be as simple ascopy(“URL”,”file”);
in theory. Cant try it out right now as I just run an aptitiude dist-upgrade (takes a while lol).
2) Probably cleaner and not using fopen-wrappers would be to use fsockopen. See examples here
http://nl2.php.net/manual/en/function.fsockopen.php
and
http://nl3.php.net/manual/en/function.stream-get-contents.php3) Theres a full http-request class which one can likely also abuse. That could get a bit more tricky.
07/12/2007 at 9:21 PM #14745masParticipantOk, finally the aptitude dist-upgrade has updated the 31 packets.
Replacing the exec(wget) with
copy($url,$imgDir.$mode.”.jpg”);
gets an error:
[07-Dec-2007 22:06:47] PHP Warning: copy(http://chart.apis.google.com/chart?cht=bvs&chbh=70,10&chg=20,10,1,5&chtt=Top 10 Decades&chd=t:1023,428,175,132,23&chs=800×300&chl=2000%20%281023%29|1990%20%28428%29|1980%20%28175%29|1970%20%28132%29|1960%20%2823%29&chco=F2BB73,0000ff,FF66ff,666666&chf=bg,lg,90,ffffff,1,A3C1E8,0.45) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
in /var/www/Friends/Musik/functions.php on line 171
It seems the $title isnt url-escaped (wget seems to fix it up) so I did a$title = urlencode($title);
right before the $url variable gets parsed and voila, all works nicely and even twice as fast
This page took 1.219778 seconds to load.
Which is no surprise as exec() needs to spawn a full bash shell which is a lot of memory for something really trivial. Another reason why exec() is “da evuhl”.
P.S.: The best and cleanest fix would be using path 2) though, as URL-fopen is also a bit dirty. But well its at least fast and no exec call.
P.P.S.:
By checking whether fopen() returns an error one could now also much easier implement a fallback to the libchart. Simply set $fallback to TRUE if fopen fails and then do an if(USE_LIBCHART or $fallback)
if(USE_GOOGLE)
{
$chd = substr($chd,0,strlen($chd)-1);
$chl = substr($chl,0,strlen($chl)-1);
$title = urlencode($title);
if(PIE==$graph)
$url = "http://chart.apis.google.com/chart?cht=p3&chtt=$title&chd=t:$chd&chs=800x300&chl=$chl&chco=F2BB73,0000ff,FF66ff,666666&chf=bg,lg,90,ffffff,1,A3C1E8,0.45";
if(BAR==$graph)
$url = "http://chart.apis.google.com/chart?cht=bvs&chbh=70,10&chg=20,10,1,5&chtt=$title&chd=t:$chd&chs=800x300&chl=$chl&chco=F2BB73,0000ff,FF66ff,666666&chf=bg,lg,90,ffffff,1,A3C1E8,0.45";
//exec("/usr/bin/wget -q -r -O "$imgDir$mode.jpg" "$url" ");
copy($url,$imgDir.$mode.".jpg");
if($output)
{
$random=rand();
print "<img alt="$title" src="$imgDir$mode.jpg?Ref=$random" ";
print "style="border: 1px solid #A3C1E8;"/>n
n";
}
}
07/12/2007 at 10:47 PM #14746sonichouseParticipant@Mas- thanks for your guidance and comments ๐
I have replaced the wget call with copy as suggested – cheers.
The Bar chart drawing is now more intelligent.
Let me know how you get on with v1.08.
/Steve
08/12/2007 at 12:42 PM #14747sonichouseParticipantYet another update for Bar Charts.
Added comments and stuff to make it easier for me to understand.Version 1.09 now uploaded.
08/12/2007 at 2:34 PM #14748sonichouseParticipantI remember from days as a developer that the cycle was :-
Code, Release, Test
or was that
Code, Test, Release
Anyway further reading of the google API suggests that values must be between 0 and 100.
I have written a routine to normalise the values passed to the chart engine, so again another version is born.
v1.11 available from the usual place.
/Steve
-
AuthorPosts
- The forum ‘Add-on Software’ is closed to new topics and replies.