Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php semaphore doesn't work

Tags:

php

semaphore

apc

I've got the following code and the semaphore wouldn't lock it as expected.

(I'm aware of apc_inc. This is not what I'm looking for.)

$semkey = sem_get(123);
sem_acquire($semkey);

$count = apc_fetch('count111');
if(!$count) $count = 0;
$count++;
apc_store('count111', $count);

sem_release($semkey);

followed by

ab -n 4000 -c 200 http://localhost/test.php

0 requests failed.

but after that an apc_fetch('count111') shows only ~ 1200 hits

nginx on ubuntu 12.04 (64bit), php 5.3.16~dotdeb, php-fpm

  • update 1: works perfectly on Linux mint, 5.4.6~dotdeb, built in web server. I'm going to try the same machine with the same version with nginx.
like image 897
Alex Avatar asked Sep 13 '12 13:09

Alex


1 Answers

The problem was, apparently, with the APC itself, not with the semaphore.
Updating to PHP 5.4.8-1~dotdeb.0 has solved the problem for both nginx and built-in server test runs.

like image 65
Alex Avatar answered Nov 03 '22 04:11

Alex