当前位置: 动力学知识库 > 问答 > 编程问答 >

How to handle multiple requests of the same form using php and mySQL?

问题描述:

I am using PHP with Zend Framework and MySQL. I have a form which users login to. When multiple users login to the same form at the same time, based on the arrival I am able to allow access(enabling the form fields) for edit to the 1st user and the other users are only able to view the 'disabled' form fields and the person who is editing right now and the Edit Queue.

When the person editing completes and logs out, how do I 'enable' the already created form fields for the next-in-line in the Queue and also modify edit queues for all?

If I have this in my main Controller:

 while(1)

{

sleep(3);

$log_firstrow = $this->getFirstRow($db);

if($this->isFirstRow($log_firstrow, $username)==1)

{

$this->view->queue = 0;

break;

}

}

This prevents view access while waiting to display the disabled form. Only after the first person logs out, and this user is next-in-line, does the controller complete and proceed to view where the form is displayed.

Thanks.

网友答案:

This will easily timeout your PHP script if someone takes his time on the editing page. Or there is a long queue. Not to mention, all persons in the queue will see a blank page as nothing will be served until the controller finishes the processing. Also, the editing page will remain blocked by an editing user if he does not log out through your application, but simply leaves the page or closes his browser.

Why don't you use AJAX so that each person in the queue polls the server every N seconds to see if it is their turn to do the editing?

分享给朋友:
您可能感兴趣的文章:
随机阅读: