lib/php_process.rb in php_process-0.0.3 vs lib/php_process.rb in php_process-0.0.5
- old
+ new
@@ -59,13 +59,17 @@
@err_thread = Knj::Thread.new do
@stderr.each_line do |str|
@args[:on_err].call(str) if @args[:on_err]
$stderr.print "Process error: #{str}" if @debug or @args[:debug_stderr]
- if str.match(/^PHP Fatal error: (.+)\s+/)
+ if str.match(/^PHP Fatal error: (.+)\s*/)
@fatal = str.strip
+ elsif str.match(/^Killed\s*$/)
+ @fatal = "Process was killed."
end
+
+ break if (!@args and str.to_s.strip.length <= 0) or (@stderr and @stderr.closed?)
end
end
$stderr.print "Waiting for PHP-script to be ready.\n" if @debug
started = false
@@ -314,9 +318,11 @@
#Starts the thread which reads answers from the PHP-process. This is called automatically from the constructor.
def start_read_loop
@thread = Knj::Thread.new do
@stdout.lines do |line|
+ break if line == nil or @stdout.closed?
+
data = line.split(":")
args = PHP.unserialize(Base64.strict_decode64(data[2].strip))
type = data[0]
id = data[1].to_i
$stderr.print "Received: #{id}:#{type}:#{args}\n" if @debug
\ No newline at end of file