Giter VIP home page Giter VIP logo

php-ext-counter's Introduction

PHP atomic counter extension

Simple SysV semaphore counter. It will be automatically undone when the process terminates.

Supported platform

  • Linux (kernel > 2.1) (not Solaris)

Install

phpize
./configure
make
make install

Add extension=counterlock.so to your php.ini configuration

Install on CentOS and RHEL

/opt/remi/php71/root/usr/bin/phpize
./configure --with-php-config=/opt/remi/php71/root/usr/bin/php-config
make
make install
echo "extension=counterlock.so" > /etc/opt/remi/php71/php.d/20-counerlock.ini

Run test

phpize
./configure
make
make test

Example Usage

<?php

$res = counter_create(1863);
echo counter_value($res) . PHP_EOL;
counter_increment($res);
echo counter_value($res) . PHP_EOL;; 
counter_decrement($res);

/* Result
0
1

Provided function.

<?php

// Start of counterlock.

/**
 * Get or create a semaphore counter id
 * 
 * @param int $key
 * @param int $perm [optional] <p>
 * The semaphore permissions. Actually this value is
 * set only if the process finds it is the only process currently
 * attached to the semaphore.
 * </p>
 *
 * @return resource a positive counter identifier on success, or <b>FALSE</b> on
 * error.
 */
function counter_create ($key, $perm = 0666) {}

/**
 * Increment a counter
 * @param resource $resource <p>
 * <i>resource</i> is a resource, obtained from <b>counter_create</b>.
 * </p>
 * @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
 */
function counter_increment ($resource) {}

/**
 * Increment a counter
 * @param resource $resource <p>
 * A resource handle as returned by
 * <b>counter_create</b>.
 * </p>
 * @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
 */
function counter_decrement ($resource) {}

/**
 * Get counter value.
 * 
 * @param resource $resource <p>
 * A resource handle as returned by
 * <b>counter_create</b>.
 * </p>
 * @return integer|false <b>FALSE</b> on failure.
 */
function counter_value ($resource) {}

/**
 * Remove a System V semaphore for counter
 * @param resource $resource <p>
 * A semaphore resource identifier as returned
 * by <b>sem_get</b>.
 * </p>
 * @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
 */
function counter_remove ($resource) {}

// End of counterlock.

php-ext-counter's People

Contributors

vtsykun avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.