Home  >  Article  >  Backend Development  >  File locking problem in Zend_Search_Lucence_PHP tutorial

File locking problem in Zend_Search_Lucence_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:55:461133browse

The file locking function in PHP is very unstable. In particular, it has a lot to do with the PHP version and platform. Today I saw the solution in Zend_Search_Lucence:

First flock a file. The lock mode is: flock($file, LOCK_EX | LOCK_NB). If the next process accesses $file again, it will no longer be able to obtain the lock of flock, so it will return a false, representing the file. It's locked and can no longer be accessed.

When Zend_Search_Lucence is locked, it is mainly: writing the index, reading the index, and optimizing the index.

 About LOCK_NB:

It is better supported under Linux, but it is not supported until PHP 5.2.1 on Windows.

Therefore, it is best to use Zend_Search_Lucence with PHP 5.2.1 or above.

If the version is lower than PHP 5.2.1, the process will wait forever (because under Windows, versions lower than PHP 5.2.1 do not support non-blocking mode locking).

 About updating the index: When updating the index, the index is often locked. Therefore, it is not recommended to update the index immediately. It is recommended to update the index at night when the number of visits is relatively small.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364340.htmlTechArticleThe file locking function in PHP is very unstable. In particular, it has a lot to do with the PHP version and platform. Today I saw the solution in Zend_Search_Lucence as follows: First fl...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn