[fpc-pascal] How to use FCGI in threaded mode?
silvioprog
silvioprog at gmail.com
Tue Feb 10 21:44:12 CET 2015
On Fri, Jan 30, 2015 at 1:25 PM, Michael Van Canneyt <michael at freepascal.org
> wrote:
>
> On Fri, 30 Jan 2015, silvioprog wrote:
>
>> But if you are on a headless server, then a windows service is the
>> only really viable way.
>>
>> You can start messing with run entries in the registry, but the
>> problem remains the same: the app must be running when the
>> webserver starts. Best way to achieve that is a service.
>>
>> The alternative is to let the webserver control the program
>> instances.
>> And except for debugging purposes, this is still the best approach
>> IMHO.
>>
>> But it is very easy to solve it. In my case, when I talk about debug an
>> application running, it isn't about debug the final executable
>> itself, but its implementation. If I start my EXE via Apache, it is
>> impossible to debug it. Using proxy, I can add another server in
>> my HTTP server (nginx allows to add more than one), something like
>> "fcgi_pass <IP of my development machine>/dev/myapp", so I open my
>> browser and access the URL of the server that is running publicly
>> (probably on a machine in the clouds), and this server will call the
>> application running here on my PC. I know my local application will be a
>> replica of the one already published, taking the time/commits
>> from the GIT log.
>>
>
> I know all this. I did this myself :)
>
> Debugging is currently not the main problem IMHO. Performance is.
>
> So I am glad you are investigating threaded fastcgi, I will be one of the
> first to test :)
>
> Although I am sure this will raise other problems when converting existing
> fastcgi processes:
> such as DB access which is not thread safe, cached data access which must
> be made thread safe etc. etc. etc.
>
> Michael.
>
Buddy, I finally could make a draft of a FastCGI application running in
multi-thread in proxy mode. =)
It worked on:
. Windows 7 - 64 bits;
. nginx 1.7.9 com o módulo FastCGI distribuído nele;
. Apache 24 (httpd-2.4.12-win64-VC11.zip), que já vem com o módulo FastCGI
com suporte ao modo proxy;
. FPC do trunk.
And the steps to test it were:
. download and unzip the attached package, after unpacking it, enter the
nginx directory and apply its settings in your copy (ainda não testei no
Linux, mas farei isso em breve I haven't tested it on Linux yet, but I'll
do it soon);
. open and run the project1.lpr project;
. open a tab in the browser and access http://localhost:81/test?op=loop, it
is supposed to be frozen for 10 seconds;
. open another tab in the browser and access http://localhost:81/test, it
is supposed to show the current time, even with the first tab frozen, this
shows that the application is working in multi-thread.
Follow attached a unit called mycustfcgi.pp, that is a copy of the trunk
custfcgi.pp. I've not created a patch because I believe that it will enter
a new class in this unit, probably called TFCGIThread, and it won't be
necessary a programmer treat the AcceptConnection method externally and not
create extra classes, like "TFastCGIThread" and "TFastCGIRouter" as in the
example.
I believe that with some tips of you, I can make this implementation by
myself and then send a patch.
It would be great if this feature has already come in FPC 3.0, which is
about to be released. =)
Thank you!
--
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150210/dd8f2d80/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FastCGI_Proxy_nginx_Apache24.zip
Type: application/zip
Size: 19374 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150210/dd8f2d80/attachment.zip>
More information about the fpc-pascal
mailing list