You are here: Home » Topic » FireStats – Top 40 php script (now with added charts)page 4

FireStats – Top 40 php script (now with added charts)

FireFly Media Server (formerly mt-daapd) Firefly Media Server Forums Firefly Media Server Add-on Software FireStats – Top 40 php script (now with added charts)

This topic contains 175 replies, has 16 voices, and was last updated by  wwarren 8 years, 9 months ago.

Viewing 15 posts - 46 through 60 (of 176 total)
  • Author
    Posts
  • #14734

    sonichouse
    Participant

    @swissy wrote:

    actually the rebuilding of the images hangs on 25 %, then nothing happens.. the topDecades.jpg has not been created even after 10 minutes !?

    Have you installed libChart ?

    If so do the example pages work ?
    Try libchart-1.2/demo/PieChartTest.php

    have you tried turning on error reporting in your php.ini ?

    #14735

    Anonymous

    is not working either…

    i’ll have a closer look at my apache config later. thnx for helping!

    #14736

    sonichouse
    Participant

    @swissy wrote:

    is not working either…

    i’ll have a closer look at my apache config later. thnx for helping!

    No problem, glad to help if it means it actually gets used by somebody.
    The only thing I can think of is GD and FreeType support.

    See http://naku.dohcrew.com/libchart/pages/introduction/gdcheck.php for more info.

    #14737

    mas
    Participant

    Just to say:

    Is working fine here with lighttpd and php-cgi5:

    PHP 5.2.3-1+b1
    lighttpd-1.4.18 (ssl)

    There were indeed a few things to enable in php.ini though (url open through file access must be enabled) and the lighttpd server must have WRITE access in the directories concerned as it writes the chart to the basedir of the script.

    Definitly look at the php.log file. It shows what is going wrong.

    The only slight problem is that its slow on a slug, but I dont think that can be helped:

    This page took 4.366378 seconds to load. (summary)
    This page took 15.977312 seconds to load. (Artist)
    This page took 14.669310 seconds to load. (Genre)
    This page took 13.459053 seconds to load. (Albums)
    This page took 1.608553 seconds to load. (Tracks)
    This page took 2.781499 seconds to load. (Decades)
    This page took 8.203721 seconds to load. (Last added)
    Refresh charts –> ages, ca. 40 secs.

    #14738

    sonichouse
    Participant

    @mas wrote:

    There were indeed a few things to enable in php.ini though (url open through file access must be enabled) and the lighttpd server must have WRITE access in the directories concerned as it writes the chart to the basedir of the script.

    I have changed version 1.06 to write to the img folder.

    @mas wrote:

    Definitly look at the php.log file. It shows what is going wrong.

    The only slight problem is that its slow on a slug, but I dont think that can be helped:

    This page took 4.366378 seconds to load. (summary)
    This page took 15.977312 seconds to load. (Artist)
    This page took 14.669310 seconds to load. (Genre)
    This page took 13.459053 seconds to load. (Albums)
    This page took 1.608553 seconds to load. (Tracks)
    This page took 2.781499 seconds to load. (Decades)
    This page took 8.203721 seconds to load. (Last added)
    Refresh charts –> ages, ca. 40 secs.

    The hit is on the pie chart generation, as you can see the decade one which has the bar chart is much quicker.

    #14739

    Anonymous

    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!

    #14740

    sonichouse
    Participant

    @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.

    #14741

    sonichouse
    Participant

    OK 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

    #14742

    mas
    Participant

    Wow 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?

    #14743

    sonichouse
    Participant

    @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 πŸ™‚

    #14744

    mas
    Participant

    @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 as

    copy(“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.php

    3) Theres a full http-request class which one can likely also abuse. That could get a bit more tricky.

    #14745

    mas
    Participant

    Ok, 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";
    }
    }
    #14746

    sonichouse
    Participant

    @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

    #14747

    sonichouse
    Participant

    Yet another update for Bar Charts.
    Added comments and stuff to make it easier for me to understand.

    Version 1.09 now uploaded.

    #14748

    sonichouse
    Participant

    I 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

Viewing 15 posts - 46 through 60 (of 176 total)

You must be logged in to reply to this topic.