todo

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· 代码 · 共 47 行

TXT
47
字号
Patrick O'Lone suggests the following idea which sounds interesting toadd as an optional mode of Cache_Lite class. (still not tested in the Cache_Lite context)-------------------------------------------------------------------------If you use the flags:ignore_user_abort(true);$fd = dio_open($szFilename, O_CREATE | O_EXCL | O_TRUNC | O_WRONLY,0644);if (is_resource($fd)) {   dio_fcntl($fd, F_SETLKW, array('type' => F_WRLCK));   dio_write($fd, $szBuffer);   dio_fcntl($fd, F_SETLK, array('type' => F_UNLCK));   dio_close($fd);}ignore_user_abort(false);Only the first process will attempt to create a file. Additionalprocesses will see that a file already exists (at the system level), andwill fail. Another thing to note is that the file descriptor must beopened using dio_open(), and certain features, like fgets() won't workwith it. If your just doing a raw write, dio_write() should be justfine. The dio_read() function should be used like:$fd = dio_open($szFilename, O_RDONLY|O_NONBLOCK, 0644);if (is_resource($fd)) {   dio_fcntl($fd, F_SETLKW, array('type' => F_RDLCK));   $szBuffer = dio_read($fd, filesize($szFilename));   dio_fcntl($fd, F_SETLK, array('type' => F_UNLCK));   dio_close($fd);}You still use locking to ensure that a write process can finish beforeanother attempts to read the file. We also set non-blocking mode in readmode so that multiple readers can access the same resource at the sametime. NOTE: Direct I/O support must be compiled into PHP for thesefeatures to work (--enable-dio).-------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?