Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-10

fp-Web and FastCGI

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, until now, I used fp-web to create cgi applications. Now I want to try fastcgi, but I don't know how to start the fascgi app.

Let me explain what I did.

1) In Lazarus I went to Project -> New -> FastCGI application. This created the skeleton for my app, very similar to a CGI app (with a TFPWebModule), but using fcgi unit instead of cgi unit.

2) Implemented a default method to just answer "Hello!".

3) After that, I compiled the program and started configuring my Apache2 (I'm on Ubuntu 10.04):

a) Edited /etc/apache2/mods-enabled/fastcgi.conf by adding with this:

<Directory "/var/www/fcgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
AddHandler fastcgi-script .fcgi

FastCgiExternalServer /var/www/cgi-bin/myfcgiprogram \ -host 127.0.0.1:2014 \
-idle-timeout 3

This tells Apache2 that, when the browser points to /cgi-bin/myfcgiprogram, it will connect to a fastcgi server running on 127.0.0.1 on port 2014.

Note: I'm configuring this the same way ExtPascal FCGI programs work, because I couln't find any help in the web nor sources of fcl-web on how to configure it.

b) Tried running my fastcgi app from command line, but it gave me this error:

exception at 0000000000466EEA:
Failed to open input-handle passed from server. Socket Error: 88.

Now I'm stuck, somebody can help me with this?.

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé
Leonardo M. Ram? wrote 6 lines
exception at 0000000000466EEA: Failed to open input-handle passed from server. Socket Error: 88. Now I'm stuck, somebody can help me with this?.

I figured out that I was configuring wrongly my apache2. Instead of using FastCgiExternalServer I changed it for this:

FastCgiServer /var/www/fcgi-bin/myfastcgiapp.fcgi -idle-timeout 3

Also, I was using a symbolic link to
/var/www/fcgi-bin/myfastcgiapp.fcgi, and now I just copied my app to that directory.

Then, I restarted apache2, and went to
http://localhost/fcgi-bin/myfastcgiapp.fcgi and, got a *more friendly* response.

I removed my TFPWebModule actions, and added just this global request handler:

procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest:
TRequest;
  AResponse: TResponse; var Handled: Boolean);
begin
  AResponse.Content := 'Hello World!';
  Handled := True;
end;

In a normal cgi app, when the user goes to
http://localhost/cgi-bin/mycgiapp.cgi, the browser should show "Hello World!", but in the case of this fastcgi app, it only shows "He", the first two characters of "Hello World!".

My environment is this:

Ubuntu 10.04 X86-64
Apache2 2.2.14
Lazarus 0.9.29 - Rev. 27637
FPC 2.5.1 - Rev. 16123

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé
Leonardo M. Ram? wrote 30 lines
On 2010-10-10 13:34:30 -0300, Leonardo M. Ram? wrote: > > exception at 0000000000466EEA: > Failed to open input-handle passed from server. Socket Error: 88. > > Now I'm stuck, somebody can help me with this?. > I figured out that I was configuring wrongly my apache2. Instead of using FastCgiExternalServer I changed it for this: FastCgiServer /var/www/fcgi-bin/myfastcgiapp.fcgi -idle-timeout 3 Also, I was using a symbolic link to /var/www/fcgi-bin/myfastcgiapp.fcgi, and now I just copied my app to that directory. Then, I restarted apache2, and went to http://localhost/fcgi-bin/myfastcgiapp.fcgi and, got a *more friendly* response. I removed my TFPWebModule actions, and added just this global request handler: procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest: TRequest; AResponse: TResponse; var Handled: Boolean); begin AResponse.Content := 'Hello World!';

You're missing

   AResponse.SendResponse;

Handled is supposed to be set only after the response has been sent.

CGI additionally checks if content was sent, but fastcgi not. Maybe we should add this check to FastCGI.

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt
Michael Van Canneyt wrote 45 lines
On Sun, 10 Oct 2010, Leonardo M. Ram? wrote: >On 2010-10-10 13:34:30 -0300, Leonardo M. Ram? wrote: >> >> exception at 0000000000466EEA: >> Failed to open input-handle passed from server. Socket Error: 88. >> >>Now I'm stuck, somebody can help me with this?. >> > >I figured out that I was configuring wrongly my apache2. Instead of >using FastCgiExternalServer I changed it for this: > > >FastCgiServer /var/www/fcgi-bin/myfastcgiapp.fcgi -idle-timeout 3 > >Also, I was using a symbolic link to >/var/www/fcgi-bin/myfastcgiapp.fcgi, and now I just copied my app to >that directory. > >Then, I restarted apache2, and went to >http://localhost/fcgi-bin/myfastcgiapp.fcgi and, got a *more friendly* >response. > >I removed my TFPWebModule actions, and added just this global request >handler: > >procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest: >TRequest; > AResponse: TResponse; var Handled: Boolean); >begin > AResponse.Content := 'Hello World!'; You're missing AResponse.SendResponse; Handled is supposed to be set only after the response has been sent. CGI additionally checks if content was sent, but fastcgi not. Maybe we should add this check to FastCGI. Michael.

Thanks Michael, I'll try that.

Reply by email

ABorka
to Michael Van Canneyt: You're missing AResponse.SendResponse; Handled is supposed to be set only after the…
Michael Van Canneyt wrote 45 lines
On Sun, 10 Oct 2010, Leonardo M. Ram? wrote: > On 2010-10-10 13:34:30 -0300, Leonardo M. Ram? wrote: >> >> exception at 0000000000466EEA: >> Failed to open input-handle passed from server. Socket Error: 88. >> >> Now I'm stuck, somebody can help me with this?. >> > > I figured out that I was configuring wrongly my apache2. Instead of > using FastCgiExternalServer I changed it for this: > > > FastCgiServer /var/www/fcgi-bin/myfastcgiapp.fcgi -idle-timeout 3 > > Also, I was using a symbolic link to > /var/www/fcgi-bin/myfastcgiapp.fcgi, and now I just copied my app to > that directory. > > Then, I restarted apache2, and went to > http://localhost/fcgi-bin/myfastcgiapp.fcgi and, got a *more friendly* > response. > > I removed my TFPWebModule actions, and added just this global request > handler: > > procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest: > TRequest; > AResponse: TResponse; var Handled: Boolean); > begin > AResponse.Content := 'Hello World!'; You're missing AResponse.SendResponse; Handled is supposed to be set only after the response has been sent. CGI additionally checks if content was sent, but fastcgi not. Maybe we should add this check to FastCGI. Michael.

Yes, please :) it would be super.
We should not have that ".SendResponse" line at all in our event handlers, just like with CGI and Apache modules with fpweb.

Handled := true; should only be checked after the event handler finished, as an indicator that the request was handled and the response was generated and can be found in the ".Content" . What is the purpose of the Handled parameter if not this with cgi/fcgi/apache_module?

AB

Reply by email

Michael Van Canneyt
to ABorka
ABorka wrote 56 lines
On 10/10/2010 11:51, Michael Van Canneyt wrote: > > > On Sun, 10 Oct 2010, Leonardo M. Ram? wrote: > >> On 2010-10-10 13:34:30 -0300, Leonardo M. Ram? wrote: >>> >>> exception at 0000000000466EEA: >>> Failed to open input-handle passed from server. Socket Error: 88. >>> >>> Now I'm stuck, somebody can help me with this?. >>> >> >> I figured out that I was configuring wrongly my apache2. Instead of >> using FastCgiExternalServer I changed it for this: >> >> >> FastCgiServer /var/www/fcgi-bin/myfastcgiapp.fcgi -idle-timeout 3 >> >> Also, I was using a symbolic link to >> /var/www/fcgi-bin/myfastcgiapp.fcgi, and now I just copied my app to >> that directory. >> >> Then, I restarted apache2, and went to >> http://localhost/fcgi-bin/myfastcgiapp.fcgi and, got a *more friendly* >> response. >> >> I removed my TFPWebModule actions, and added just this global request >> handler: >> >> procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest: >> TRequest; >> AResponse: TResponse; var Handled: Boolean); >> begin >> AResponse.Content := 'Hello World!'; > > You're missing > > AResponse.SendResponse; > > Handled is supposed to be set only after the response has been sent. > > CGI additionally checks if content was sent, but fastcgi not. > Maybe we should add this check to FastCGI. > > Michael. Yes, please :) it would be super. We should not have that ".SendResponse" line at all in our event handlers, just like with CGI and Apache modules with fpweb. Handled := true; should only be checked after the event handler finished, as an indicator that the request was handled and the response was generated and can be found in the ".Content" . What is the purpose of the Handled parameter if not this with cgi/fcgi/apache_module?

Check whether the request was handled. The request response may be empty, as in notification methods. I have many request handlers which use a ContentStream, and which send the response and free the content stream at once. So after the request was handled, there is no 'content' any more.

But I will add the check in FastCGI/Apache.
The framework must be consistent, after all :-)

Michael.

Reply by email