Home PHP Libraries Other libraries Beanstalkd PHP library
PHP client library for Beanstalkd

Beanstalk, a high-performance, lightweight distributed memory queue system, was originally designed to reduce the page access delay of high-capacity web application systems by asynchronously executing time-consuming tasks in the background. It has supported 9.5 million User's Facebook Causes application.

Later open sourced, PostRank is now deployed and used on a large scale, processing millions of tasks every day. Beanstalkd is a typical Memcached-like design. The protocol and usage are the same, so users who have used memcached will feel that Beanstalkd looks familiar.

High performance cannot be separated from asynchronous, and asynchronous cannot be separated from queues, and internally they are the principles of the Producer-Comsumer model.

Beanstalkd’s PHP client library

#!/usr/bin/env php
<?php
define('BASE_DIR', realpath(__DIR__.'/..'));
define('PHAR_FILENAME', 'pheanstalk.phar');
define('PHAR_FULLPATH', BASE_DIR.'/'.PHAR_FILENAME);
// ----------------------------------------
reexecute_if_phar_readonly($argv);
delete_existing_pheanstalk_phar();
build_pheanstalk_phar();
verify_pheanstalk_phar();
exit(0);
// ----------------------------------------
// See: http://www.php.net/manual/en/phar.configuration.php#ini.phar.readonly
function reexecute_if_phar_readonly($argv)
{
    if (ini_get('phar.readonly') && !in_array('--ignore-readonly', $argv)) {
        $command = sprintf(
            'php -d phar.readonly=0 %s --ignore-readonly',
            implode($argv, ' ')
        );
        echo "Phar configured readonly in php.ini; attempting to re-execute:\n";
        echo "$command\n";
        passthru($command, $exitStatus);
        exit($exitStatus);
    }
}
function delete_existing_pheanstalk_phar()
{
    if (file_exists(PHAR_FULLPATH)) {
        printf("- Deleting existing %s\n", PHAR_FILENAME);
        unlink(PHAR_FULLPATH);
    }
}
function build_pheanstalk_phar()
{
    printf("- Building %s from %s\n", PHAR_FILENAME, BASE_DIR);
    $phar = new Phar(PHAR_FULLPATH);
    $phar->buildFromDirectory(BASE_DIR);
    $phar->setStub(
        $phar->createDefaultStub('vendor/autoload.php')
    );
}
function verify_pheanstalk_phar()
{
    $phar = new Phar(PHAR_FULLPATH);
    printf("- %s built with %d files.\n", PHAR_FILENAME, $phar->count());
}


Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

Memcache vs. Memcached: Which PHP Library Should You Choose? Memcache vs. Memcached: Which PHP Library Should You Choose?

09 Nov 2024

Distinguishing "Memcache" and "Memcached" in PHPPHP offers two memcached libraries: memcache and memcached. Understanding their differences helps...

How Do I Link Static Libraries That Depend on Other Static Libraries? How Do I Link Static Libraries That Depend on Other Static Libraries?

13 Dec 2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

Memcache vs Memcached: Which PHP Memcached Library Should You Choose? Memcache vs Memcached: Which PHP Memcached Library Should You Choose?

19 Nov 2024

Memcache vs Memcached: Choosing the Right PHP Memcached LibraryIntroductionPHP offers two seemingly similar memcached libraries: memcache and...

Which PHP Library Best Fits Your Email Address Validation Needs? Which PHP Library Best Fits Your Email Address Validation Needs?

18 Nov 2024

PHP Email Address Validation Libraries UncoveredEmail address validation plays a crucial role in data validation, but creating a...

laravel - What should the standardized PHP class library naming look like? laravel - What should the standardized PHP class library naming look like?

06 Jul 2016

I have seen many open source projects in the form of class.classname.php, but I have also seen many frameworks in the form of classname.class.php. Where should I place this class? I personally prefer the .class.php form, because in some frameworks, after importing third-party class libraries and specifying class libraries...

Memcache vs. Memcached: Which PHP Caching Library Should You Choose? Memcache vs. Memcached: Which PHP Caching Library Should You Choose?

12 Nov 2024

Memcache vs. Memcached: Choosing the Right PHP Library for Your Cache NeedsIn the realm of PHP caching libraries, Memcache and Memcached stand out...

See all articles