<div dir="ltr"><div><div>Hello,</div><div><br></div><div>Using the TCustomHTTPApplication class, I just set the "Threaded" property to true, and my application works in threaded mode. But, how to do the same in TCustomFCgiApplication class?</div><div><br></div><div>To test it, compile and run the code below. After, open two tabs in your browser. In tab 1, open the "<a href="http://localhost/test?op=loop">http://localhost/test?op=loop</a>" URL, in tab 2, open the "<a href="http://localhost/test">http://localhost/test</a>" URL. Notice that the tab 2 will wait 10 seconds to show the result.</div><div><br></div><div><div>program project1;</div><div><br></div><div>{$mode objfpc}{$H+}</div><div><br></div><div>uses</div><div>{$IFDEF UNIX}</div><div> CThreads,</div><div>{$ENDIF}</div><div> CustWeb, HttpDefs, CustFCGI, Classes, SysUtils;</div><div><br></div><div>type</div><div><br></div><div> { TMyFCGIApplication }</div><div><br></div><div> TMyFCGIApplication = class(TCustomFCgiApplication)</div><div> protected</div><div> function InitializeWebHandler: TWebHandler; override;</div><div> end;</div><div><br></div><div> { TMyFCGIHandler }</div><div><br></div><div> TMyFCGIHandler = class(TFCGIHandler)</div><div> public</div><div> procedure HandleRequest(ARequest: TRequest; AResponse: TResponse); override;</div><div> end;</div><div><br></div><div> { TMyFCGIApplication }</div><div><br></div><div> function TMyFCGIApplication.InitializeWebHandler: TWebHandler;</div><div> begin</div><div> Result := TMyFCGIHandler.Create(Self);</div><div> end;</div><div><br></div><div> { TMyFCGIHandler }</div><div><br></div><div> procedure TMyFCGIHandler.HandleRequest(ARequest: TRequest; AResponse: TResponse);</div><div> var</div><div> I: Integer;</div><div> begin</div><div> if ARequest.QueryFields.Values['op'] = 'loop' then</div><div> begin</div><div> for I := 1 to 10 do</div><div> Sleep(1000);</div><div> AResponse.Contents.Text := 'Done!';</div><div> end</div><div> else</div><div> AResponse.Contents.Text :=</div><div> 'Now: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Now);</div><div> end;</div><div><br></div><div>begin</div><div> with TMyFCGIApplication.Create(nil) do</div><div> try</div><div> Port := 8080;</div><div> Run;</div><div> finally</div><div> Free;</div><div> end;</div><div>end.</div></div><div><br></div><div>Thank you!</div><div><br></div>-- <br><div class="gmail_signature">Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>