Recent

Author Topic: when is the web module is created / destroyed?  (Read 374 times)

egsuh

  • Sr. Member
  • ****
  • Posts: 464
when is the web module is created / destroyed?
« on: May 24, 2020, 08:58:53 am »
Hi,
I've developed a web-server application using fpweb.  Two webserver applications with the same TFPWebModules, one in CGI and another in FCGI.

With CGI model, I have two TFPWebModules (let's say wm1, wm2) and one TDataModule (dm1).  DM1 contains database access and common functions.

My question is, I cannot put any of these modules in the "Auto-create forms". They are just in available forms.

Well, the web modules (wm1 and wm2) seem to be created automatically because the application works even I did nothing to create them.

But where should I create dm1? 

Well, I can put it in the OnDataModuleCreate event handler of wm1. For example,

Code: Pascal  [Select][+][-]
  1. procedure Twm1.DataModuleCreate(Sender: TObject);
  2. begin
  3.    dm1 := Tdm1.Create(nil);
  4.    Log('wm1 created')
  5. end;
  6.  

But then,  Twm1.DataModuleDestroy is not called even in the CGI model. So I cannot destroy dm1.
If I access web-server again, the dm1 is created again. This is quite big memory loss.

When are the web modules are created? And how can I destroy them?


trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 996
  • Former Delphi 1-7, 10.2 User
Re: when is the web module is created / destroyed?
« Reply #1 on: May 24, 2020, 02:55:16 pm »
I'm not familiar with web and data modules, but I have written many CGI programs. As for destroying modules, this should surely happen by default when the CGI program terminates. CGI programs are not persistent. They get loaded by a request to the web server, they run and then they (should) terminate.

Perhaps your CGI programs are not terminating for some reason?
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

egsuh

  • Sr. Member
  • ****
  • Posts: 464
Re: when is the web module is created / destroyed?
« Reply #2 on: May 25, 2020, 10:17:16 am »
Quote
Perhaps your CGI programs are not terminating for some reason?

That depends on the module kind. If I set it as wkOneShot, it is automatically terminated.  But not if set to wkPooled. In CGI module, this should not make any differnece, but it does. It seems to be a kind of bug (I think this is already reported to bug-tracker).

 

TinyPortal © 2005-2018