Ruby Vs. PHP pipe terminal access

I’m attempting to make a javascript/RoR site that utilizes maxima the
free math program. In this thread
Maxima and Ruby Integration - Rails - Ruby-Forum I was able to pass
information into and out of maxima, but I wasn’t able to retrieve the
last line, and when running this code multiple times:

max = IO.popen(“maxima”, “w+”)
max.puts “1+1;”
response = max.gets
max.close

I get a new instances (found via ps -A) of “ttys000 0:00.00 (sbcl)”
every time i run the code. And i can’t kill this “sbcl” via “kill pid”.
I also get
“ttys000 0:00.05 sbcl --core
/opt/local/lib/maxima/5.15.0/binary-sbcl/maxima.core --noinform
–end-runtime-options --eval (cl-user::run) --end-toplevel-options”

(my version of maxima runs on a version of lisp known as SBCL)

After a few dozen requests I get this error:
http://www.pastie.org/380263

I know that piping into maxima can provide an adequate connection
solution via PHP utilizing this (working) code from the WMI project:

http://pastie.org/380232

If you have any php system piping experience, or any ruby piping
experience (or maybe both). Can you provide any tips??