开发者

Java Synchronized concept in PHP

Condition

I have comma separated list of airway bill numbers in a record in ta开发者_如何学Cble core_config_data. This table uses engine Innodb.

I have a class with a function to take read this record, explode it, unshift one airway bill number, implode rest and save in database again.

Problem

When 2 or more people press assign airway bill number at same instance, all the shipment get same airway bill numbers.

Question

Is there a way in php / magento / zend to implement synchronized for this kind of situation.

Regards, Saurabh


You can use locks, but I suggest to create a table for airway bill numbers.

SELECT counter_field FROM child_codes FOR UPDATE;
UPDATE child_codes SET counter_field = counter_field + 1;

http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html


  • You could use redis for this with blpop/push.(performs best I guess)
  • You could use http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_get-lock
  • You should also read about transactions => http://en.wikipedia.org/wiki/Database_transaction
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜