You are here: Home » Reply

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



Ok, finally the aptitude dist-upgrade has updated the 31 packets.

Replacing the exec(wget) with


gets an error:

[07-Dec-2007 22:06:47] PHP Warning: copy(,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.

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)

$chd = substr($chd,0,strlen($chd)-1);
$chl = substr($chl,0,strlen($chl)-1);

$title = urlencode($title);

$url = "$title&chd=t:$chd&chs=800x300&chl=$chl&chco=F2BB73,0000ff,FF66ff,666666&chf=bg,lg,90,ffffff,1,A3C1E8,0.45";

$url = ",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" ");

print "<img alt="$title" src="$imgDir$mode.jpg?Ref=$random" ";
print "style="border: 1px solid #A3C1E8;"/>n