💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Lock swoole1.6.4版本增加了锁的实现。PHP代码中可以很方便地创建一个锁,用来实现数据同步。swoole_lock类支持5种锁的类型: 1. 文件锁 SWOOLE_FILELOCK 2. 读写锁 SWOOLE_RWLOCK 3. 信号量 SWOOLE_SEM 4. 互斥锁 SWOOLE_MUTEX 5. 自旋锁 SWOOLE_SPINLOCK **注意:请勿在`onReceive`等回调函数中创建锁,否则底层的`GlobalMemory`内存会持续增长,造成内存泄漏。** 示例: ----- ```php $lock = new swoole_lock(SWOOLE_MUTEX); echo "[Master]create lock\n"; $lock->lock(); if (pcntl_fork() > 0) { sleep(1); $lock->unlock(); } else { echo "[Child] Wait Lock\n"; $lock->lock(); echo "[Child] Get Lock\n"; $lock->unlock(); exit("[Child] exit\n"); } echo "[Master]release lock\n"; unset($lock); sleep(1); echo "[Master]exit\n"; ```