Re: PostgreSQL locking from PHP scripts - Mailing list pgsql-php

From Rick Morris
Subject Re: PostgreSQL locking from PHP scripts
Date
Msg-id 45503B48.6020803@brainscraps.com
Whole thread Raw
In response to Re: PostgreSQL locking from PHP scripts  (Chris <dmagick@gmail.com>)
List pgsql-php
Chris wrote:
> Herbie McDuck wrote:
>> Alan Hodgson wrote:
>>> On Thursday 26 October 2006 11:11, Amal burman
>>> <amalburman@yahoo.com> wrote:
>>>
>>>> postgresql database for this project. Here script one
>>>> (booking.php) tries to setup a lock for update and ask
>>>> user to fill-up the form. Now when the user fill-up
>>>> the form and submit it for update, second script
>>>> (update.php) update the database and releasing the
>>>> locks.
>>>
>>> You can't do this kind of thing in PHP.  PHP resets the database
>>> connection between scripts.   The script is finished as soon as the
>>> page is delivered to the client.
>>>
>>> Also, web connections are stateless and there is no way to even know
>>> what web server process or database connection you'll be getting on
>>> subsequent page views.
>> So is PHP and 'ANY' database a useless adventure when it goes to
>> developing a robust business and accounting package?
>
> No, it applies to anything you do in a web browser.
>
> The HTTP protocol is "stateless" which means all resources,
> connections etc are killed at the end of the script. Resources of any
> type are not kept alive at the end of a script.
>
> It's not a php thing or <insert random language here>, it's a HTTP
> protocol thing.
>
There is another way to approach this with PHP and other random
languages, as long as scripts can be executed outside of the context of
an HTTP server module (such as PHP in CLI mode): have a the web script
interact with a standalone commandline script or daemon that lives
across requests. Thus your HTTP-requested PHP script could communicate
via some IPC method to a PHP-CLI script which holds the database
connections, binds them to a session ID and actually handles the
mechanics of transactions and queries (a simple connection pooling
method, if you will) and thus transactions can be maintained across
multiple requests.

Now, saying it and doing it are two different things, I understand; not
exactly trivial to implement. But still, if it is important enough to
your application, it can be done. And, I have found PHP to be quite
stable running in daemon mode. At least, amply stable enough to handle
transactions that span minutes or hours. (I have had PHP daemon scripts
run for weeks without problem)



pgsql-php by date:

Previous
From: Herbie McDuck
Date:
Subject: Re: PostgreSQL locking from PHP scripts
Next
From: Robert Treat
Date:
Subject: Re: PostgreSQL locking from PHP scripts