Home php教程 php手册 Linux下安装gearman并安装php扩展模块

Linux下安装gearman并安装php扩展模块

Jun 06, 2016 pm 07:53 PM
gearman linux php Install Expand module

Gearman介绍 earman提供了一种通用的程序框架来将你的任务分发到不同的机器或者不同的进程当中。它提供了你进行并行工作的能力、负载均衡处理的能力,以及在不同程序语言之间沟通的能力。Gearman能够应用的领域非常广泛,从高可用的网站到数据库的复制任务。

Gearman介绍

earman提供了一种通用的程序框架来将你的任务分发到不同的机器或者不同的进程当中。它提供了你进行并行工作的能力、负载均衡处理的能力,以及在不同程序语言之间沟通的能力。Gearman能够应用的领域非常广泛,从高可用的网站到数据库的复制任务。总之,Gearman就是负责分发处理的中枢系统,它的优点包括:

     开源:Gearman免费并且开源而且有一个非常活跃的开源社区,如果你想来做一些贡献,请点击 。

     多语言支持:Gearman支持的语言种类非常丰富。让我们能够用一种语言来编写Worker程序,但是用另外一种语言编写Client程序。

     灵活:不必拘泥于固定的形式。您可以采用你希望的任何形式,例如 Map/Reduce。

     快速:Gearman的协议非常简单,并且有一个用C语言实现的,经过优化的服务器,保证应用的负载在非常低的水平。

     可植入:因为Gearman非常小巧、灵活。因此您可以将他置入到现有的任何系统中。

     没有单点:Gearman不仅可以帮助扩展系统,同样可以避免系统的失败。


Gearman的工作原理


使用Gearman的应用通常有三部分组成:一个Client、一个Worker、一个 任务服务器。 Client的作用是提出一个 Job 任务 交给 Job Server 任务服务器。Job Server 会去寻找一个 合适的 Worker 来完成这项任务。Worker 执行由 Client 发送过来的 Job,并且将结果通过 Job Server 返回给 Client。Gearman 提供了 Client 和 Worker 的 API,利用这些API 应用可以同 Gearman Job Server来进行通信。Gearman 内部 Client 和 Worker 之间的通信都是通过 TCP 连接来进行的。工作的流程如下图所示:


Linux下安装gearman并安装php扩展模块



Gearman的用处


Gearman首先提供了一个多语言通讯的接口,当然还有比这个更简单有效的办法。Gearman可以将工作的负载分担到不同的机器中,如下图所示:


Linux下安装gearman并安装php扩展模块


Job Server 可以开启多个实例,这样在其中一个发生故障的时候,可以 Failover 到其他的机器上。同时 Worker 也可以是多个实例进行运行,因为当前的服务器很多都是多核的。


Gearman要依赖于 Boost C++ Libraries 中的 program_options 库,并且需要的版本大于 1.39。


Gearman安装

1、准备安装文件

     服务端文件gearmand下载地址:https://launchpad.net/gearmand/+download

    php扩展gearman下载地址:http://pecl.php.net/package/gearman

    *注意 最好安装最新的版本,因为以前的版本可能有些bug

2、解压安装(安装需要有超级用户的权限,即根用户权限)。

$ tar zxf gearmand-1.1.7.tar.gz
$ cd gearmand-1.1.7
$ ./configure
$ make
$ sudo make install
Copy after login

这里安装可能出现错误
<span>checking </span><span>for</span><span>Boost</span><span> headers version </span><span>>=</span><span>1.39</span><span>.</span><span>0.</span><span>..</span><span>no</span><span>
configure</span><span>:</span><span> error</span><span>:</span><span> cannot find </span><span>Boost</span><span> headers version </span><span>>=</span><span>1.39</span><span>.</span><span>0</span>
Copy after login
如果嫌麻烦就直接yum install boost

接着要安装libevent-devel不然也会报错

安装 gearmand 后,构建 PHP 扩展。

$ cd /opt/software/
#
# tar zxf gearman-1.1.1.tgz
$ cd <span>gearman-1.1.1.tgz</span>

Copy after login

有了这些代码后,就可以开始构建扩展了:

$ /usr/local/php/bin/phpize
$ ./configure
$ make
$ sudo make install
Copy after login



都安装完成后在php的配置文件中加入extension="gearman.so"

最后运行php查看phpinfo()是否已经安装,如下图所示:

我的运行环境是nginx+php-cgi方式运行的,首先启动nginx /usr/local/nginx/sbin/nginx,然后启动php-cgi /usr/local/

php/bin/php-cgi -b 127.0.0.1:9000 -c /usr/local/php/etc/php.ini



Gearman的高级特性

在一个 Web 应用程序内可能有许多地方都会用到 Gearman。可以导入大量数据、发送许多电子邮件、编码视频文件、挖据数据并构建一个中央日志设施 — 所有这些均不会影响站点的体验和响应性。可以并行地处理数据。而且,由于 Gearman 协议是独立于语言和平台的,所以您可以在解决方案中混合编程语言。比如,可以用 PHP 编写一个 producer,用 C、Ruby 或其他任何支持 Gearman 库的语言编写 worker。

一个连接客户机和 worker 的 Gearman 网络实际上可以使用任何您能想象得到的结构。很多配置能够运行多个代理并将 worker 分配到许多机器上。负载均衡是隐式的:每个可操作的可用 worker(可能是每个 worker 主机具有多个 worker)从队列中拉出作业。一个作业能够同步或异步运行并具有优先级。

Gearman 的最新版本已经将系统特性扩展到了包含持久的作业队列和用一个新协议来通过 HTTP 提交工作请求。对于前者,Gearman 工作队列保存在内存并在一个关系型数据库内存有备份。这样一来,如果 Gearman 守护程序故障,它就可以在重启后重新创建这个工作队列。另一个最新的改良通过一个 memcached 集群增加队列持久性。memcached 存储也依赖于内存,但被分散于几个机器以避免单点故障。

Gearman 是一个刚刚起步却很有实力的工作分发系统。据 Gearman 的作者 Eric Day 介绍,Yahoo! 在 60 或更多的服务器上使用 Gearman 每天处理 600 万个作业。新闻聚合器 Digg 也已构建了一个相同规模的 Gearman 网络,每天可处理 400,000 个作业。Gearman 的一个出色例子可以在 Narada 这个开源搜索引擎(参见 参考资料)中找到。

Gearman 的未来版本将收集并报告统计数据、提供高级监视和缓存作业结果等。为了跟踪这个 Gearman 项目,可以订阅它的 Google 组,或访问 Freenode 上它的 IRC 频道



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHP and the Web: Exploring its Long-Term Impact PHP and the Web: Exploring its Long-Term Impact Apr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

See all articles