PDA

View Full Version : halp



Rob Oplawar
July 3rd, 2008, 02:49 PM
you probably won't be able to help me with this, but it's worth a shot.

I'm currently working on a web based application for my job, and right now I need to get 2D plotting capability in it. I'm currently running Linux, using PHP to generate the views, and I'm trying to use gnuplot to generate the plots. So if you don't know gnuplot and Linux, you won't be able to help me here.

So, I have my php script, gnuplot.php, which inspects the query string for parameters for the plot, and then uses proc_open to get a gnuplot process running. I feed the data into gnuplot, and then send it the plot command, and then I send a Content-type:image/png header and echo out the gnuplot stdout stream.

Problem is, I'm not getting that far- when I send gnuplot the plot command, it sends me back this message:

gnuplot: symbol lookup error
gnuplot: undefined symbol: gdImageSetAntiAliased
Gnuplot works just fine when I'm running it from a terminal, even when I su to www-data, which is the user that Apache runs as, and I'm pretty sure that's the user PHP runs as, and gnuplot runs as a child process of that.
... fake edit: oops, I just ran a top -u www-data, and that's not reporting any processes under that name... am I just failing at my usage of top, or is apache actually running as a different user?

Aaaaanyway, I did a google search on the error I'm getting, and I can't turn up anything. I can't figure out what is wrong with this thing, and I need to get 2D plotting working before next week (I can work over the 3 day weekend). I'd post on a forum devoted to php or gnuplot or the like, except that whenever I do that I get on average about 1 response every 5 days, and even then it's completely unhelpful.

[/longpost]

tl;dr: Anybody here know Linux, PHP/Apache, and gnuplot? Plz help!

e: so I tried skipping the stdout thing and setting output to a file, but it always gives me a permission denied error. Even when I try setting output to STDOUT it tells me permission denied. What the fuck. This is annoying.

klange
July 3rd, 2008, 03:41 PM
You're using a library that lacks the function gdImageSetAntiAliased, which for some reason PHP is trying to use. It really sounds like an incompatible set of binaries and libraries, though, is everything gnuplot-related up to date?


(Apache doesn't technically run as www-data, but uses it for accessing files)

Rob Oplawar
July 3rd, 2008, 03:48 PM
what user does Apache run under?
I checked, and as far as I can tell gnuplot and everything it uses is up to date.
I can't find any reports of people using gnuplot in php having this permission denied error, either.
Here's the thing- if I tell it to write a file to /tmp, it does it without complaining. If I tell it to write anywhere else, even in directories with full r/w/x permissions, even to friggin STDOUT, it tells me permission denied.

:/

Rob Oplawar
July 7th, 2008, 03:27 PM
bumplepost:

several days later... still no luck. I'm dying here. This is producing a huge delay on my product. ARG.

Rob Oplawar
July 8th, 2008, 06:05 PM
http://www.unlimitedgamer.net/coverage/halo2/images/medal_006.gif
So I gave up on Linux and tried it in Windows, and now it seems I've got it working. Close enough.


I'm wondering if I can get some input on an algorithm I'm using. I can't post the code because technically it belongs to NASA, as I am working under a contract for a contract for said administration. However, I think I can get away with posting the general algorithm.

So I want to plot an arbitrary number of variables across an arbitrary timespan. What I do is iterate across tics along the timespan, and then iterate across all the variables I'm plotting, and there I run a mysql query for values in the database for that variable with timestamp between some range specified by the current tic:



for i from 1 to number of horizontal pixels
begin = beginning of range covered by pixel i
end = end of range covered by pixel i
for j from 1 to number of variables
SELECT value FROM table WHERE index = j AND timestamp BETWEEN begin AND end LIMIT 1

This way an 800 pixel image can cover 500,000 data points without actually plotting all 500,000 (and believe me, with the data I'm working with, this is necessary)- instead it only fetches at most 800 data points because that's the resolution the image can display.

So this is working just fine for me, but I'm curious. Does anybody know of any better/cleaner/more efficient way of doing this? Specifically, is there an SQL construct that allows you to do what I've done above, so that I can get rid of one or both for loops and have the result of the query be my entire result set, instead of getting a single result per query?
I mean, say I had a 1000 pixel image with 10 variables plotted on it- that's 10,000 queries. It works, but it seems ugly to me.