Re: Getting the process ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Rasmus Lerdorf" <rasmus@xxxxxxxxxxx> wrote in message 
news:42435332.70807@xxxxxxxxxxxxxx
> Joshua Beall wrote:
>> I am doing some work where I want to do locking, and prevent scripts from 
>> running in parallel.  I see that I could use the semaphore mechanism, but 
>> I'd like for my code to be portable, and that extension is not enabled in 
>> many places.
>
> Sort of defeats the whole concept of a web server, but to answer just your 
> process id question, use getmypid()

http://php.net/manual/en/function.getmypid.php

It says "Process IDs are not unique"

I really only need it to be unique at any given instant.  I can do 
sha1(microtime().getmypid()) to generate a unique ID.  But of course it is 
only guaranteed to be unique if indeed the process ID is not shared.

The problem I am having is that people are double-submitting certain 
transactions.  My first attempt to prevent this was to store a flag in the 
session record indicating whether or not certain transactions had been 
completed, but this turned out to be insufficient at times because users 
could try and initiate a second transaction before the first transaction had 
finished (and thus the system had not yet flagged the transaction completed 
in the session record).  They then both completed in parallel, and voila, 
duplicate transactions again.

I realized that this sort of problem would always exist unless I had some 
sort of semaphore mechanism.  Once a user has *started* a transaction, they 
need to be prevented from initiating a second transaction until the first 
transaction has been completed.

I am open to suggestions on how to do this.  What is the best way?

  -Josh 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux