Forum Moderators: coopster

Message Too Old, No Replies

One session should complete a php function before other session enter

         

kijkij

5:29 am on Dec 20, 2010 (gmt 0)

10+ Year Member




Suppose that I have a function in php like:

function post_data()
{

// Do the job
}

Now I want this function to complete for the current visitor first before other visitors enter the function. Other visitors should pass this function and do the remaining script jobs. I searched for this problem too much but could not find a proper answer. What I found is that to use flock() php function. I tried flock() and it worked best for me but I want an independent solution to this.

So how can this function be locked for one visitor before other enter the function without using flock()?

Matthew1980

8:56 am on Dec 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there kijkij,

Could you possibly 'lock' this function out if it is use by an IP address, then once the IP address var is empty, then the function is ready to be used?

Not attempted anything like this myself, but I think the logic is sound. Just thought I should offer that suggestion, there may be other more effective methods, but can't think of one off hand..

Cheers,
MRb

kijkij

10:24 am on Dec 20, 2010 (gmt 0)

10+ Year Member




Thanks Mathew,

As far as I know about the variables they are available to the current session and each session has its own variable values. May be you can clear it more with some example.

What I want to do is write a cron job function. So when I schedule a cron job it should run at that time and re-schedule the job for next time. But the problem is if 2 or more visitors enter at the same time then they will read the cron time variable of same value and will run all at once the same function. Thats why I want it to finish first visitor at first and other should bypass the function.