찾다
백엔드 개발PHP 문제PHP용 사육사 확장 프로그램을 설치하는 방법

PHP에서 사육사 확장을 설치하는 방법: 먼저 사육사를 다운로드한 다음 마지막으로 "make && make install"을 통해 사육사를 설치합니다.

PHP용 사육사 확장 프로그램을 설치하는 방법

이 문서의 운영 환경: Windows 7 시스템, PHP7.1, Dell G3 컴퓨터.

ZooKeeper는 분산형 오픈소스 분산 애플리케이션 조정 서비스로, Google의 Chubby를 오픈소스로 구현한 것이며 Hadoop 및 Hbase의 중요한 구성 요소입니다. 분산 애플리케이션에 일관된 서비스를 제공하는 소프트웨어입니다. 제공되는 기능에는 구성 유지 관리, 도메인 이름 서비스, 분산 동기화, 그룹 서비스 등이 있습니다.

ZooKeeper의 목표는 복잡하고 오류가 발생하기 쉬운 핵심 서비스를 캡슐화하여 사용자에게 간단하고 사용하기 쉬운 인터페이스와 효율적인 성능과 안정적인 기능을 갖춘 시스템을 제공하는 것입니다.

PHP에서 Zookeeper를 사용하려면 먼저 PHP Zookeeper 확장을 설치해야 합니다. PHP Zookeeper 확장을 설치하려면 먼저 Zookeeper를 설치해야 합니다

1. Zookeeper를 설치하세요

여기에서 최신 안정 버전을 다운로드하세요

http://mirror .bit.edu.cn/apache/zookeeper/stable/

cd /download

wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz // 이것은 이미 설치된 도구입니다. 나중에 PHP 확장을 설치할 때 사용되므로 직접 컴파일하고 설치해야 합니다.

tar -zxvf Zookeeper-3.4.12.tar.gz

cd Zookeeper-3.4.12/ src /c/

./configure --prefix=/usr/local/zookeeper //설치 디렉터리 지정

make && make install

설치가 완료되었습니다

2. http:/에서 PHP Zookeeper 확장 프로그램을 설치하세요. / pecl.php.net/package/zookeeper

cd /download

wget http://pecl.php.net/get/zookeeper-0.6.2.tgz

tar -zxvf Zookeeper-0.6.2에서 찾으세요. tgz

cd Zookeeper-0.6.2

./configure --with-libzookeeper-dir=/usr/local/zookeeper //종속성을 지정하려면

make && make install

php.ini 구성

extension=" / usr/local/Cellar/php/7.2.6/pecl/20170718/zookeeper.so"

php-fpm을 다시 시작하세요.

【권장사항: "PHP Video Tutorial"】

3. Zookeeper를 시작하기 전에 jdk를 설치하세요. 이미 설치된 것은 무시해도 됩니다.

http://www.oracle.com/technetwork/java/javase/downloads /jdk8 -downloads-2133151.html에서

을 다운로드한 다음 간단한 방법으로 설치합니다. 여기서는 다루지 않겠습니다.

4 Zookeeper

cd /download/zookeeper-3.4를 시작합니다. 12/bin

./zkServer.sh start

./zkCli.sh -server 127.0.0.1:2181

cli 모드 open

참고:

오류가 보고되는 경우:

cd ../conf

cp Zoo_sample.cfg Zoo .cfg

파일 복사

5. PHP 코드 테스트

테스트 코드

  1. <?php
     
    /**
     
     * 
     
     */
     
    class zookeeperDemo
     
    {
     
    private $zookeeper;
     
    function __construct($address)
     
    {
     
    $this->zookeeper = new Zookeeper($address);
     
    }
     
    /*
     
     * get 
     
     */
     
    public function get($path)
     
    {
     
    if (!$this->zookeeper->exists($path)) {
     
    return null;
     
    }
     
    return $this->zookeeper->get($path);
     
    }
     
     
     
    public function getChildren($path) {
     
    if (strlen($path) > 1 && preg_match(&#39;@/$@&#39;, $path)) {
     
    // remove trailing /
     
    $path = substr($path, 0, -1);
     
    }
     
    return $this->zookeeper->getChildren($path);
     
    }
     
    /*
     
     * set 值
     
     *
     
     *
     
     */
     
    public function set($path, $value)
     
    {
     
    if (!$this->zookeeper->exists($path)) {
     
    //创建节点
     
    $this->makePath($path);
     
    } else {
     
    $this->zookeeper->set($path,$value);
     
    }
     
     
     
    }
     
    /*
     
     * 创建路径
     
     */
     
    private function makePath($path, $value=&#39;&#39;)
     
    {
     
    $parts = explode(&#39;/&#39;, $path);
     
    $parts = array_filter($parts);//过滤空值
     
    $subPath = &#39;&#39;;
     
    while (count($parts) > 1) {
     
    $subPath .= &#39;/&#39; . array_shift($parts);//数组第一个元素弹出数组
     
    if (!$this->zookeeper->exists($subpath)) {
     
    $this->makeNode($subPath, $value);
     
    }
     
    }
     
    }
     
    /*
     
     * 创建节点
     
     *
     
     */
     
    private function makeNode($path, $value, array $params = array())
     
    {
     
    if (empty($params)) {
     
    $params = [
     
    [
     
    &#39;perms&#39; => Zookeeper::PERM_ALL,
     
    &#39;scheme&#39; => &#39;world&#39;,
     
    &#39;id&#39; => &#39;anyone&#39;
     
    ]
     
    ];
     
    }
     
    return $this->zookeeper->create($path, $value, $params);
     
    }
     
    /*
     
     * 删除
     
     **/
     
    public function deleteNode($path)
     
    {
     
    if (!$this->zookeeper->exists($path)) {
     
    return null;
     
    } else {
     
    return $this->zookeeper->delete($path);
     
    }
     
    }
     
     
     
    }
     
    $zk = new zookeeperDemo(&#39;localhost:2181&#39;);
     
    //var_dump($zk->get(&#39;/zookeeper&#39;));
     
    var_dump($zk->getChildren(&#39;/foo&#39;));
     
    //var_dump($zk->deleteNode("/foo"));
     
     
     
    ?>
    测试代码2、
     
    <?php
     
    /**
     
     * PHP Zookeeper
     
     *
     
     * PHP Version 5.3
     
     *
     
     * The PHP License, version 3.01
     
     *
     
     * @category Libraries
     
     * @package PHP-Zookeeper
     
     * @author Lorenzo Alberton <l.alberton@quipo.it>
     
     * @copyright 2012 PHP Group
     
     * @license http://www.php.net/license The PHP License, version 3.01
     
     * @link https://github.com/andreiz/php-zookeeper
     
     */
     
    /**
     
     * Example interaction with the PHP Zookeeper extension
     
     *
     
     * @category Libraries
     
     * @package PHP-Zookeeper
     
     * @author Lorenzo Alberton <l.alberton@quipo.it>
     
     * @copyright 2012 PHP Group
     
     * @license http://www.php.net/license The PHP License, version 3.01
     
     * @link https://github.com/andreiz/php-zookeeper
     
     */
     
    class Zookeeper_Example
     
    {
     
    /**
     
     * @var Zookeeper
     
     */
     
    private $zookeeper;
     
    /**
     
     * @var Callback container
     
     */
     
    private $callback = array();
     
    /**
     
     * Constructor
     
     *
     
     * @param string $address CSV list of host:port values (e.g. "host1:2181,host2:2181")
     
     */
     
    public function __construct($address) {
     
    $this->zookeeper = new Zookeeper($address);
     
    }
     
    /**
     
     * Set a node to a value. If the node doesn&#39;t exist yet, it is created.
     
     * Existing values of the node are overwritten
     
     *
     
     * @param string $path The path to the node
     
     * @param mixed $value The new value for the node
     
     *
     
     * @return mixed previous value if set, or null
     
     */
     
    public function set($path, $value) {
     
    if (!$this->zookeeper->exists($path)) {
     
    $this->makePath($path);
     
    $this->makeNode($path, $value);
     
    } else {
     
    $this->zookeeper->set($path, $value);
     
    }
     
    }
     
    /**
     
     * Equivalent of "mkdir -p" on ZooKeeper
     
     *
     
     * @param string $path The path to the node
     
     * @param string $value The value to assign to each new node along the path
     
     *
     
     * @return bool
     
     */
     
    public function makePath($path, $value = &#39;&#39;) {
     
    $parts = explode(&#39;/&#39;, $path);
     
    $parts = array_filter($parts);
     
    $subpath = &#39;&#39;;
     
    while (count($parts) > 1) {
     
    $subpath .= &#39;/&#39; . array_shift($parts);
     
    if (!$this->zookeeper->exists($subpath)) {
     
    $this->makeNode($subpath, $value);
     
    }
     
    }
     
    }
     
    /**
     
     * Create a node on ZooKeeper at the given path
     
     *
     
     * @param string $path The path to the node
     
     * @param string $value The value to assign to the new node
     
     * @param array $params Optional parameters for the Zookeeper node.
     
     * By default, a public node is created
     
     *
     
     * @return string the path to the newly created node or null on failure
     
     */
     
    public function makeNode($path, $value, array $params = array()) {
     
    if (empty($params)) {
     
    $params = array(
     
    array(
     
    &#39;perms&#39; => Zookeeper::PERM_ALL,
     
    &#39;scheme&#39; => &#39;world&#39;,
     
    &#39;id&#39; => &#39;anyone&#39;,
     
    )
     
    );
     
    }
     
    return $this->zookeeper->create($path, $value, $params);
     
    }
     
    /**
     
     * Get the value for the node
     
     *
     
     * @param string $path the path to the node
     
     *
     
     * @return string|null
     
     */
     
    public function get($path) {
     
    if (!$this->zookeeper->exists($path)) {
     
    return null;
     
    }
     
    return $this->zookeeper->get($path);
     
    }
     
    /**
     
     * List the children of the given path, i.e. the name of the directories
     
     * within the current node, if any
     
     *
     
     * @param string $path the path to the node
     
     *
     
     * @return array the subpaths within the given node
     
     */
     
    public function getChildren($path) {
     
    if (strlen($path) > 1 && preg_match(&#39;@/$@&#39;, $path)) {
     
    // remove trailing /
     
    $path = substr($path, 0, -1);
     
    }
     
    return $this->zookeeper->getChildren($path);
     
    }
     
     
     
    /**
     
     * Delete the node if it does not have any children
     
     * 
     
     * @param string $path the path to the node
     
     * 
     
     * @return true if node is deleted else null
     
     */
     
     
     
    public function deleteNode($path)
     
    {
     
    if(!$this->zookeeper->exists($path))
     
    {
     
    return null;
     
    }
     
    else
     
    {
     
    return $this->zookeeper->delete($path);
     
    }
     
    }
     
     
     
    /**
     
     * Wath a given path
     
     * @param string $path the path to node
     
     * @param callable $callback callback function
     
     * @return string|null
     
     */
     
    public function watch($path, $callback)
     
    {
     
    if (!is_callable($callback)) {
     
    return null;
     
    }
     
     
     
    if ($this->zookeeper->exists($path)) {
     
    if (!isset($this->callback[$path])) {
     
    $this->callback[$path] = array();
     
    }
     
    if (!in_array($callback, $this->callback[$path])) {
     
    $this->callback[$path][] = $callback;
     
    return $this->zookeeper->get($path, array($this, &#39;watchCallback&#39;));
     
    }
     
    }
     
    }
     
     
     
    /**
     
     * Wath event callback warper
     
     * @param int $event_type
     
     * @param int $stat
     
     * @param string $path
     
     * @return the return of the callback or null
     
     */
     
    public function watchCallback($event_type, $stat, $path)
     
    {
     
    if (!isset($this->callback[$path])) {
     
    return null;
     
    }
     
     
     
    foreach ($this->callback[$path] as $callback) {
     
    $this->zookeeper->get($path, array($this, &#39;watchCallback&#39;));
     
    return call_user_func($callback);
     
    }
     
    }
     
     
     
    /**
     
     * Delete watch callback on a node, delete all callback when $callback is null
     
     * @param string $path
     
     * @param callable $callback
     
     * @return boolean|NULL
     
     */
     
    public function cancelWatch($path, $callback = null)
     
    {
     
    if (isset($this->callback[$path])) {
     
    if (empty($callback)) {
     
    unset($this->callback[$path]);
     
    $this->zookeeper->get($path); //reset the callback
     
    return true;
     
    } else {
     
    $key = array_search($callback, $this->callback[$path]);
     
    if ($key !== false) {
     
    unset($this->callback[$path][$key]);
     
    return true;
     
    } else {
     
    return null;
     
    }
     
    }
     
    } else {
     
    return null;
     
    }
     
    }
     
    }
     
    $zk = new Zookeeper_Example(&#39;localhost:2181&#39;);
     
    // var_dump($zk->get(&#39;/&#39;));
     
    // var_dump($zk->getChildren(&#39;/&#39;));
     
    // var_dump($zk->set(&#39;/test&#39;, &#39;abc&#39;));
     
    // var_dump($zk->get(&#39;/test&#39;));
     
    // var_dump($zk->getChildren(&#39;/&#39;));
     
    // var_dump($zk->set(&#39;/foo/001&#39;, &#39;bar1&#39;));
     
    // var_dump($zk->set(&#39;/foo/002&#39;, &#39;bar2&#39;));
     
    // var_dump($zk->get(&#39;/&#39;));
     
    // var_dump($zk->getChildren(&#39;/&#39;));
     
    // var_dump($zk->getChildren(&#39;/foo&#39;));
     
     
     
    //watch example 一旦/test节点的值被改变,就会调用一次callback
     
    function callback() {
     
    echo "in watch callback\n";
     
    }
     
    //$zk->set(&#39;/test&#39;, 1);
     
    $ret = $zk->watch(&#39;/test&#39;, &#39;callback&#39;); 
     
    //$zk->set(&#39;/test&#39;, 2);//在终端执行
     
    while (true) {
     
    sleep(1);
     
    }
     
     
     
    /*
     
    class ZookeeperDemo extends Zookeeper {
     
     
     
     public function watcher( $i, $type, $key ) {
     
     echo "Insider Watcher\n";
     
     
     
     // Watcher gets consumed so we need to set a new one
     
     
     
    //ZooKeeper提供了可以绑定在znode的监视器。如果监视器发现znode发生变化,该service会立即通知所有相关的客户端。这就是PH//P脚本如何知道变化的。Zookeeper::get方法的第二个参数是回调函数。当触发事件时,监视器会被消费掉,所以我们需要在回调函
     
    //数中再次设置监视器。
     
     
     
     $this->get( &#39;/test&#39;, array($this, &#39;watcher&#39; ) );
     
     
     
     }
     
     
     
    }
    
    $zoo = new ZookeeperDemo(&#39;127.0.0.1:2181&#39;);
    $zoo->get( &#39;/test&#39;, array($zoo, &#39;watcher&#39; ) );
    while( true ) {
     echo &#39;.&#39;;
     sleep(2);
    }
    */
    /*
    
    // $zc = new Zookeeper();
     
    // $zc->connect(&#39;127.0.0.1:2181&#39;);
    // var_dump($zc->get(&#39;/zookeeper&#39;));
    // exit;
    */
     
    ?>

코드 참조 링크:

https://github.com /php-zookeeper/php-zookeeper/blob/master/examples/ Zookeeper_Example.php

위 내용은 PHP용 사육사 확장 프로그램을 설치하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
산과 기본 데이터베이스 : 차이 및 각각을 사용 해야하는시기.산과 기본 데이터베이스 : 차이 및 각각을 사용 해야하는시기.Mar 26, 2025 pm 04:19 PM

이 기사는 산 및 기본 데이터베이스 모델을 비교하여 특성과 적절한 사용 사례를 자세히 설명합니다. 산은 금융 및 전자 상거래 애플리케이션에 적합한 데이터 무결성 및 일관성을 우선시하는 반면 Base는 가용성 및

PHP 보안 파일 업로드 : 파일 관련 취약점 방지.PHP 보안 파일 업로드 : 파일 관련 취약점 방지.Mar 26, 2025 pm 04:18 PM

이 기사는 코드 주입과 같은 취약점을 방지하기 위해 PHP 파일 업로드 보안에 대해 설명합니다. 파일 유형 유효성 검증, 보안 저장 및 오류 처리에 중점을 두어 응용 프로그램 보안을 향상시킵니다.

PHP 입력 유효성 검증 : 모범 사례.PHP 입력 유효성 검증 : 모범 사례.Mar 26, 2025 pm 04:17 PM

기사는 내장 함수 사용, 화이트리스트 접근 방식 및 서버 측 유효성 검사와 같은 기술에 중점을 둔 보안을 향상시키기 위해 PHP 입력 유효성 검증에 대한 모범 사례를 논의합니다.

PHP API 요율 제한 : 구현 전략.PHP API 요율 제한 : 구현 전략.Mar 26, 2025 pm 04:16 PM

이 기사는 토큰 버킷 및 누출 된 버킷과 같은 알고리즘을 포함하여 PHP에서 API 요율 제한을 구현하고 Symfony/Rate-Limiter와 같은 라이브러리 사용 전략에 대해 설명합니다. 또한 모니터링, 동적 조정 요율 제한 및 손도 다룹니다.

PHP 비밀번호 해싱 : password_hash 및 password_verify.PHP 비밀번호 해싱 : password_hash 및 password_verify.Mar 26, 2025 pm 04:15 PM

이 기사에서는 PHP에서 암호를 보호하기 위해 PHP에서 Password_hash 및 Password_Verify 사용의 이점에 대해 설명합니다. 주요 주장은 이러한 기능이 자동 소금 생성, 강한 해싱 알고리즘 및 Secur를 통해 암호 보호를 향상 시킨다는 것입니다.

OWASP Top 10 PHP : 일반적인 취약점을 설명하고 완화하십시오.OWASP Top 10 PHP : 일반적인 취약점을 설명하고 완화하십시오.Mar 26, 2025 pm 04:13 PM

이 기사는 PHP 및 완화 전략의 OWASP Top 10 취약점에 대해 설명합니다. 주요 문제에는 PHP 응용 프로그램을 모니터링하고 보호하기위한 권장 도구가 포함 된 주입, 인증 파손 및 XSS가 포함됩니다.

PHP XSS 예방 : XSS로부터 보호하는 방법.PHP XSS 예방 : XSS로부터 보호하는 방법.Mar 26, 2025 pm 04:12 PM

이 기사는 PHP의 XSS 공격을 방지하기위한 전략, 입력 소독, 출력 인코딩 및 보안 향상 라이브러리 및 프레임 워크 사용에 중점을 둔 전략에 대해 설명합니다.

PHP 인터페이스 대 추상 클래스 : 각각을 사용할 때.PHP 인터페이스 대 추상 클래스 : 각각을 사용할 때.Mar 26, 2025 pm 04:11 PM

이 기사는 각각의 사용시기에 중점을 둔 PHP의 인터페이스 및 추상 클래스 사용에 대해 설명합니다. 인터페이스는 관련없는 클래스 및 다중 상속에 적합한 구현없이 계약을 정의합니다. 초록 클래스는 일반적인 기능을 제공합니다

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

안전한 시험 브라우저

안전한 시험 브라우저

안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

SublimeText3 영어 버전

SublimeText3 영어 버전

권장 사항: Win 버전, 코드 프롬프트 지원!

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)