search
HomePHP LibrariesOther librariesBeanstalkd 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

Looking for a php/python library management program (similar to Baidu library, managing doc/pdf and other libraries)Looking for a php/python library management program (similar to Baidu library, managing doc/pdf and other libraries)

30Sep2016

Looking for a php/python library management program (similar to Baidu library, managing doc/pdf and other libraries)~~ It mainly needs to have search functions, especially file classification retrieval/file tag retrieval functions, no need for online conversion, online browsing!

Integration of PHP function library and third-party libraryIntegration of PHP function library and third-party library

22Apr2024

Function libraries and third-party libraries in PHP can extend the functionality of applications. The function library provides predefined functions that can be included through the include statement. Third-party libraries are available from sources such as Packagist, GitHub, and installed using Composer. Implement automatic loading of classes through autoloaders, such as automatic loading of the Guzzle library. Learn how to use the Dompdf third-party library to generate PDF files through practical cases, including loading the library, loading HTML content, and outputting PDF files. The integration of function libraries and third-party libraries greatly expands the functionality of PHP applications and improves development efficiency and project performance.

How to write a PHP function library?How to write a PHP function library?

17Apr2024

The steps for writing a function library in PHP are as follows: Create a PHP file (such as myFunctions.php) to store the functions. Use the function keyword to define functions in a file. Include libraries in other scripts using require_once or include_once statements. Once a function library is included, its functions can be used.

How to create a PHP library and make it support different PHP versions?How to create a PHP library and make it support different PHP versions?

26Apr2024

PHP function libraries can improve code reusability by encapsulating common tasks. To create a reusable library that supports different PHP versions: define the library and compatible PHP version ranges; handle version differences based on PHP version; package the library for use by other projects.

PHP library collectionPHP library collection

29Jul2016

:This article mainly introduces the collection of PHP libraries. Students who are interested in PHP tutorials can refer to it.

How is the PHP function library organized?How is the PHP function library organized?

11Apr2024

PHP function libraries are organized in independent files according to different functions and uses, including core extensions (/ext/), core libraries (/libs/), PEAR function libraries (/pear/) and user-defined functions (/user/). With this organization, developers can easily reuse and extend code while maintaining modularity and maintainability.

See all articles