There are two different ways to do this:
\ 1. In ruby, configure a non-HTTP server that listens only to "::" (or 127.0.0.1 if you don't like ipv6). Then, every time your PHP script needs to do something, it can connect to the server and pass data to it. This would be the fastest solution because ruby script does not need to be run every time PHP has to do something.
Ruby example:
require 'mechanize'
require 'socket'
def do_mechanize_stuff(command, *args)
case command
when 'search_google'
when 'answer_questions_on_stackoverflow'
end
'the result to pass to PHP'
end
srv = TCPServer.new '::', 3000
loop do
Thread.new(srv.accept) do |sock|
sock.write(
do_mechanize_stuff *sock.gets.split(' ')
)
sock.close
end
end
Ruby client example: (you need to translate this to PHP)
require 'socket'
s = TCPSocket.new 'localhost', 3000
s.puts 'search_google how to use a keyboard'
until (r = s.gets).nil?
print r
end
, http://god.rubyforge.org/, .
\ 2. ruby script exec PHP .
script:
require 'mechanize'
def do_mechanize_stuff(command, *args)
end
do_mechanize_stuff ARGV.shift, ARGV