Jens
Jens

Reputation: 25563

Communication with php fastcgi socket from ruby

I wish to check correct php fastcgi operation from a ruby script. Do do that, I just wanted to send a simple PHP script to the socket and check for the correct return value.

Now, I am new to both ruby and sockets, so I tried

require 'socket'

s = UNIXSocket.new("/var/run/php/php.socket")
s.send('<?php print "Hello World"; ?>', 0)
puts s.recv(11)

but I get

test.rb:5:in `recv': Connection reset by peer - recvfrom(2) (Errno::ECONNRESET)
          from test.rb:5:in `<main>'

Google is less than helpful, because 'PHP' triggers too many tutorials on how to use sockets from php.

I know that the php socket works correctly (since it powers my website). How could I get my script to correctly receive "Hello World"?

Upvotes: 1

Views: 963

Answers (1)

akirk
akirk

Reputation: 6837

FastCGI has a binary protocol that you would need to implement. So in the end you'd better use a library that has already implemented it for you.

After all you might be better off by simply using a bash script and a program installed by the libfcgi library (apt-get install libfcgi-dev on Debian), for example

SCRIPT_FILENAME=/path/test.php cgi-fcgi -bind -connect /var/run/php/php.socket

(Jens corrected my original example for his environment in a comment, thanks)

Upvotes: 3

Related Questions