Re: [Lazarus] fpWeb long process progress

2012-08-15 Thread Michael Van Canneyt



On Tue, 14 Aug 2012, Leonardo M. Ramé wrote:


On 2012-08-14 11:47:41 -0300, Marcos Douglas wrote:

IMHO, maybe is better to use CGI gateway to capture the requests and,
for each one them, start a process -- this method will use a file to
write the log of process, as Leonardo and Michael said.



Yes, in my case, I know in advance the process wouldn't take more than
one minute, but for longer processes the gateway is a nice idea.


Well, I use the code I sent to take backups or fix databases, which 
takes 30 minutes easily. The browser just polls ever so-and-so time.


Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-15 Thread Michael Schnell

On 08/15/2012 12:14 AM, Leonardo M. Ramé wrote:
in my case, I know in advance the process wouldn't take more than one 
minute,
I feel that (without some special configuration) a normal web server 
will kill a standard CGI process that takes more than just a few seconds 
before returning.


Please check the specs of your Webserver and let us know what you find.

-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-15 Thread Henry Vermaak
On 15 August 2012 09:28, Michael Schnell mschn...@lumino.de wrote:
 On 08/15/2012 12:14 AM, Leonardo M. Ramé wrote:

 in my case, I know in advance the process wouldn't take more than one
 minute,

 I feel that (without some special configuration) a normal web server will
 kill a standard CGI process that takes more than just a few seconds before
 returning.

Apache defaults to 300 seconds for its core timeout (which includes
mod_cgi).  Different modules have their own configuration settings,
e.g. php have a max_execution_time, which defaults to 30 seconds
afaik.

Henry

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread michael . vancanneyt



On Mon, 13 Aug 2012, Leonardo M. Ramé wrote:


On 2012-08-13 15:15:56 -0700, leledumbo wrote:

How can I send responses by intervals?


AFAIK that's not the way web application works. It's the client that should
be querying the server in a regular interval (using AJAX request perhaps).
The server can track current progress status and return that right away when
asked.



Yes, I know that, but I thought Lazarus have something easy to develop
such process.

The way I'm thinking of implementing is this:

1) The client app asks the server (a CGI process) for a process ID, for
example 123, by calling getProcId.
2) Using this ID, the client calls the time-consuming task, passing the
ID. for example, runTask(Id). At this time, the server launches a
program passing the ID for the task. This must be a multi-thread
program, because it can be asked for running many tasks, and can be
asked for the status of each task. The program only finishes when the
last task is ended.
3) The client calss a getProcStatus(ID) method. The server, using IPC or
Pipes, asks the already-launched process for its status.


I have code which does exactly that. It's used in production. 
It's unix-only, however (it relies on fork and exec).


If you're interested, I can send you the code.

Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread Michael Schnell
AFAIK, a web application uses the plain old standard mechanism, a web 
server uses to work with a CGI application. it start the application and 
when same ends, the web server retrieves its output and sends it to the 
browser. So the web application just does not live long to be able to 
wait for anything.


To create a longer living web enabled process it takes a lot more effort.

You can try several approaches:

 - purely propriety: Use a second process (a long living daemon) and 
have the web application communicate with same (e.g. via TCP/IP or Pipe)
 - fast CGI: here the (Apache) Web Server does exactly this 
communication on it's own account

 - ISAPI: here a (Microsoft) Web server communicates with a DLL

My colleagues do a combination of (1) and (3) with one of their (Delphi) 
project very successfully:


They created a very simple ISAPI DLL (using RemObjects to do the ISAPI 
communication)


They created a Windows service  and used RemObjects (using the Windows 
Message transport) to have the ISAPI DLL communicate with the service.


(RemObjects is a commercial product that is specified to work as well 
with Delphi as with FreePascal.)


-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread Michael Schnell

On 08/14/2012 09:06 AM, michael.vancann...@wisa.be wrote:


I have code which does exactly that. It's used in production. It's 
unix-only, however (it relies on fork and exec).



GREAT !

It would be great if this would be integrated in the Lazarus 
distribution (as a special Application)  or if it would be available 
as an add-on package.


Thanks,
-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread Leonardo M . Ramé
On 2012-08-14 09:47:41 +0200, Michael Schnell wrote:
 AFAIK, a web application uses the plain old standard mechanism, a
 web server uses to work with a CGI application. it start the
 application and when same ends, the web server retrieves its output
 and sends it to the browser. So the web application just does not
 live long to be able to wait for anything.
 
 To create a longer living web enabled process it takes a lot more effort.
 
 You can try several approaches:
 
  - purely propriety: Use a second process (a long living daemon) and
 have the web application communicate with same (e.g. via TCP/IP or
 Pipe)
  - fast CGI: here the (Apache) Web Server does exactly this
 communication on it's own account
  - ISAPI: here a (Microsoft) Web server communicates with a DLL
 
 My colleagues do a combination of (1) and (3) with one of their
 (Delphi) project very successfully:
 
 They created a very simple ISAPI DLL (using RemObjects to do the
 ISAPI communication)
 
 They created a Windows service  and used RemObjects (using the
 Windows Message transport) to have the ISAPI DLL communicate with
 the service.
 
 (RemObjects is a commercial product that is specified to work as
 well with Delphi as with FreePascal.)
 
 -Michael

Thanks Michael, I'm testing a different approach, based on a temporary
file. It works this way:

1) The client asks for a TaskId, for example 1234.
2) With the TaskId generated by the server, the client calls a CGI
method called runLongTask(myTaskId). This method writes a temporary file
which name is the taskId. 
3) The client can ask for status by using a method called
getTaskStatus(myTaskId).

This way I can run a long task without having to create a daemon.

Regards,
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread Leonardo M . Ramé
On 2012-08-14 09:06:20 +0200, michael.vancann...@wisa.be wrote:
 
 
 On Mon, 13 Aug 2012, Leonardo M. Ramé wrote:
 
 On 2012-08-13 15:15:56 -0700, leledumbo wrote:
 How can I send responses by intervals?
 
 AFAIK that's not the way web application works. It's the client that should
 be querying the server in a regular interval (using AJAX request perhaps).
 The server can track current progress status and return that right away when
 asked.
 
 
 Yes, I know that, but I thought Lazarus have something easy to develop
 such process.
 
 The way I'm thinking of implementing is this:
 
 1) The client app asks the server (a CGI process) for a process ID, for
 example 123, by calling getProcId.
 2) Using this ID, the client calls the time-consuming task, passing the
 ID. for example, runTask(Id). At this time, the server launches a
 program passing the ID for the task. This must be a multi-thread
 program, because it can be asked for running many tasks, and can be
 asked for the status of each task. The program only finishes when the
 last task is ended.
 3) The client calss a getProcStatus(ID) method. The server, using IPC or
 Pipes, asks the already-launched process for its status.
 
 I have code which does exactly that. It's used in production. It's
 unix-only, however (it relies on fork and exec).
 
 If you're interested, I can send you the code.
 
 Michael.

Yes please, send me the code.

Regards,
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread michael . vancanneyt



On Tue, 14 Aug 2012, Leonardo M. Ramé wrote:


On 2012-08-14 09:47:41 +0200, Michael Schnell wrote:

AFAIK, a web application uses the plain old standard mechanism, a
web server uses to work with a CGI application. it start the
application and when same ends, the web server retrieves its output
and sends it to the browser. So the web application just does not
live long to be able to wait for anything.

To create a longer living web enabled process it takes a lot more effort.

You can try several approaches:

 - purely propriety: Use a second process (a long living daemon) and
have the web application communicate with same (e.g. via TCP/IP or
Pipe)
 - fast CGI: here the (Apache) Web Server does exactly this
communication on it's own account
 - ISAPI: here a (Microsoft) Web server communicates with a DLL

My colleagues do a combination of (1) and (3) with one of their
(Delphi) project very successfully:

They created a very simple ISAPI DLL (using RemObjects to do the
ISAPI communication)

They created a Windows service  and used RemObjects (using the
Windows Message transport) to have the ISAPI DLL communicate with
the service.

(RemObjects is a commercial product that is specified to work as
well with Delphi as with FreePascal.)

-Michael


Thanks Michael, I'm testing a different approach, based on a temporary
file. It works this way:

1) The client asks for a TaskId, for example 1234.
2) With the TaskId generated by the server, the client calls a CGI
method called runLongTask(myTaskId). This method writes a temporary file
which name is the taskId.
3) The client can ask for status by using a method called
getTaskStatus(myTaskId).

This way I can run a long task without having to create a daemon.


That is exactly what I do.

Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread michael . vancanneyt



On Tue, 14 Aug 2012, Leonardo M. Ramé wrote:



I have code which does exactly that. It's used in production. It's
unix-only, however (it relies on fork and exec).

If you're interested, I can send you the code.

Michael.


Yes please, send me the code.


Sent in private mail.

Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread Michael Schnell

On 08/14/2012 04:27 PM, Leonardo M. Ramé wrote:
2) With the TaskId generated by the server, the client calls a CGI 
method called runLongTask(myTaskId).
I don't know if it's a goad idea to allow a standard CGI to do a 
long action before returning top the WebServer.


At least the WebServer might kill the child task after a few seconds if 
it thinks it has run wild.


Maybe it is possible to configure the appropriate Timeout in the web 
server parameters.


-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread Marcos Douglas
On Tue, Aug 14, 2012 at 11:34 AM, Michael Schnell mschn...@lumino.de wrote:
 On 08/14/2012 04:27 PM, Leonardo M. Ramé wrote:

 2) With the TaskId generated by the server, the client calls a CGI method
 called runLongTask(myTaskId).

 I don't know if it's a goad idea to allow a standard CGI to do a long
 action before returning top the WebServer.

+1

 At least the WebServer might kill the child task after a few seconds if it
 thinks it has run wild.

 Maybe it is possible to configure the appropriate Timeout in the web server
 parameters.

IMHO, maybe is better to use CGI gateway to capture the requests and,
for each one them, start a process -- this method will use a file to
write the log of process, as Leonardo and Michael said.

Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-14 Thread Leonardo M . Ramé
On 2012-08-14 11:47:41 -0300, Marcos Douglas wrote:
 IMHO, maybe is better to use CGI gateway to capture the requests and,
 for each one them, start a process -- this method will use a file to
 write the log of process, as Leonardo and Michael said.
 

Yes, in my case, I know in advance the process wouldn't take more than
one minute, but for longer processes the gateway is a nice idea.

Regards,
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-13 Thread leledumbo
 How can I send responses by intervals?

AFAIK that's not the way web application works. It's the client that should
be querying the server in a regular interval (using AJAX request perhaps).
The server can track current progress status and return that right away when
asked.



--
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-fpWeb-long-process-progress-tp4025614p4025615.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-13 Thread Leonardo M . Ramé
On 2012-08-13 15:15:56 -0700, leledumbo wrote:
  How can I send responses by intervals?
 
 AFAIK that's not the way web application works. It's the client that should
 be querying the server in a regular interval (using AJAX request perhaps).
 The server can track current progress status and return that right away when
 asked.
 

Yes, I know that, but I thought Lazarus have something easy to develop
such process.

The way I'm thinking of implementing is this:

1) The client app asks the server (a CGI process) for a process ID, for
example 123, by calling getProcId.
2) Using this ID, the client calls the time-consuming task, passing the
ID. for example, runTask(Id). At this time, the server launches a
program passing the ID for the task. This must be a multi-thread
program, because it can be asked for running many tasks, and can be
asked for the status of each task. The program only finishes when the
last task is ended.
3) The client calss a getProcStatus(ID) method. The server, using IPC or
Pipes, asks the already-launched process for its status.

Regards,
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] fpWeb long process progress

2012-08-13 Thread Marcos Douglas
On Mon, Aug 13, 2012 at 7:31 PM, Leonardo M. Ramé l.r...@griensu.com wrote:

 On 2012-08-13 15:15:56 -0700, leledumbo wrote:
   How can I send responses by intervals?
 
  AFAIK that's not the way web application works. It's the client that
  should
  be querying the server in a regular interval (using AJAX request
  perhaps).
  The server can track current progress status and return that right away
  when
  asked.
 

 Yes, I know that, but I thought Lazarus have something easy to develop
 such process.

 The way I'm thinking of implementing is this:

 1) The client app asks the server (a CGI process) for a process ID, for
 example 123, by calling getProcId.
 2) Using this ID, the client calls the time-consuming task, passing the
 ID. for example, runTask(Id). At this time, the server launches a
 program passing the ID for the task. This must be a multi-thread
 program, because it can be asked for running many tasks, and can be
 asked for the status of each task. The program only finishes when the
 last task is ended.
 3) The client calss a getProcStatus(ID) method. The server, using IPC or
 Pipes, asks the already-launched process for its status.

Your program is the main thread. For each request your program should
create a new thread to process. Each thread synchronizes with the main
thread (your program) about it your own status.

Already exists an example with the same idea (more or less)... in
Pascal... called ExtPascal.

Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus