takuya/php-sysv-ipc-semaphore 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

takuya/php-sysv-ipc-semaphore

最新稳定版本:0.3.2

Composer 安装命令:

composer require takuya/php-sysv-ipc-semaphore

包简介

php sysv semaphore wrapper

README 文档

README

This package is wrapper for php sysv sem_xxx. And with string $name

Installing

from Packagist

composer require takuya/php-sysv-ipc-semaphore

from GitHub

name='php-sysv-ipc-semaphore' composer config repositories.$name \ vcs https://github.com/takuya/$name composer require takuya/$name:master composer install

Examples

<?php $uniq_name = 'semphore_name'; $semaphore = new IPCSemaphore($uniq_name); $semaphore->acquire();// first acquire must be success. $semaphore->acquire(true);// multiple acquired result true $semaphore->release(); // // remove from IPC // $semaphore->destroy();

More easy way to use semaphore

Using semaphore with callback

<?php $semaphore = new IPCSemaphore('semphore_name'); $ret = $semaphore->withLock(function(){ // do something in lock echo "run in lock"; return 1234; }); $ret === 1234; //=> true

Using easy locking ( release() by destructor ).

<?php function RunWithLock(){ $semaphore = new IPCSemaphore('sem_name'); // $lock is local scope. // auto released by destructor on garbage collection. $lock = $semaphore->lock(); return 1234; } ///  RunWithLock();

Using semaphore with try-finally

<?php function sample($msg){ try { $sem = new IPCSemaphore(str_rand(10)); $sem->acquire(); return $msg; // finally called before return. } finally { $sem->release(); } }

semaphore and thread-mutex

Compare to Thread and SyncMutex , SysV semaphore has one big advantage in PHP.

SysV function (ex sem_get) is bundled with PHP, no required PECL.

But, sem_get() does not accept string named. This package utilize pseudo string $name.

remove ipc by manually

If unused ipc remains. use SHELL command to remove.

ipcs -s | grep $USER | grep -oE '0x[a-f0-9]+' | xargs -I@ ipcrm --semaphore-key @

统计信息

  • 总下载量: 4.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固