Discussion:
[PHP] pcntl_fork() and database concurrency
(too old to reply)
Andre Lopes
15 years ago
Permalink
Hi,

I need to write a PHP Script to use with a Crontab. That Crontab will run
every 10 minutes.

I should use pcntl_fork() to prevent concurrency in database queries, but I
don't have sure how to use this PHP function.

The reason for use this function is to prevent that if the Crontab don't do
the Job in 10 minutes, the next Cronjob will not concur with the job in the
background that is running.

My question. There are PostgreSQL examples on how to use this function to
prevent database concurrency?

Best Regards,
Andre Lopes
15 years ago
Permalink
Hi,

Thanks for the reply.

I forgot to said that I will send e-mails in this process, so I need to
interact with the Database and with the PHP.

This approach is valid for this kind of problem?


I have seen some procedures in SQL Server with row locks(I think this is the
term) to the tables in Selects and Updates. PostgreSQL have this mechanisms?

Best Regards,
...
Andrew McMillan
15 years ago
Permalink
Post by Andre Lopes
Hi,
Thanks for the reply.
I forgot to said that I will send e-mails in this process, so I need
to interact with the Database and with the PHP.
This approach is valid for this kind of problem?
Sure. You're just storing a row in the database, checking whether you
successfully did so, and quitting if you didn't. It should be valid for
any problem where you don't want two processes to be happening
concurrently.

Equally you could run your PHP program from a shell script and use some
lockfile program to do a similar thing, but I actually think that the
SQL solution is cleaner, and I trust the ACID capabilities of the
database much more than those of the filesystem.
Post by Andre Lopes
I have seen some procedures in SQL Server with row locks(I think this
is the term) to the tables in Selects and Updates. PostgreSQL have
this mechanisms?
You could use row locking, but I don't think it gives as much potential
for discovering what/why something is locked, and personally I would
consider it likely to be less imediately understood by a programmer
returning to the code in a couple of years. Whereas anyone who does SQL
knows how UPDATE & SELECT work, they probably have to refer to the
manual to work out exactly what LOCK does.

Cheers,
Andrew.
...
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
Q: How much does it cost to ride the Unibus?
A: 2 bits.
------------------------------------------------------------------------
Loading...