PHP용 사육사 확장 프로그램을 설치하는 방법
PHP에서 사육사 확장을 설치하는 방법: 먼저 사육사를 다운로드한 다음 마지막으로 "make && make install"을 통해 사육사를 설치합니다.
이 문서의 운영 환경: 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 코드 테스트
테스트 코드
<?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('@/$@', $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='') { $parts = explode('/', $path); $parts = array_filter($parts);//过滤空值 $subPath = ''; while (count($parts) > 1) { $subPath .= '/' . array_shift($parts);//数组第一个元素弹出数组 if (!$this->zookeeper->exists($subpath)) { $this->makeNode($subPath, $value); } } } /* * 创建节点 * */ private function makeNode($path, $value, array $params = array()) { if (empty($params)) { $params = [ [ 'perms' => Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone' ] ]; } 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('localhost:2181'); //var_dump($zk->get('/zookeeper')); var_dump($zk->getChildren('/foo')); //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'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 = '') { $parts = explode('/', $path); $parts = array_filter($parts); $subpath = ''; while (count($parts) > 1) { $subpath .= '/' . 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( 'perms' => Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone', ) ); } 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('@/$@', $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, 'watchCallback')); } } } /** * 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, 'watchCallback')); 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('localhost:2181'); // var_dump($zk->get('/')); // var_dump($zk->getChildren('/')); // var_dump($zk->set('/test', 'abc')); // var_dump($zk->get('/test')); // var_dump($zk->getChildren('/')); // var_dump($zk->set('/foo/001', 'bar1')); // var_dump($zk->set('/foo/002', 'bar2')); // var_dump($zk->get('/')); // var_dump($zk->getChildren('/')); // var_dump($zk->getChildren('/foo')); //watch example 一旦/test节点的值被改变,就会调用一次callback function callback() { echo "in watch callback\n"; } //$zk->set('/test', 1); $ret = $zk->watch('/test', 'callback'); //$zk->set('/test', 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( '/test', array($this, 'watcher' ) ); } } $zoo = new ZookeeperDemo('127.0.0.1:2181'); $zoo->get( '/test', array($zoo, 'watcher' ) ); while( true ) { echo '.'; sleep(2); } */ /* // $zc = new Zookeeper(); // $zc->connect('127.0.0.1:2181'); // var_dump($zc->get('/zookeeper')); // exit; */ ?>
로그인 후 복사
코드 참조 링크:
https://github.com /php-zookeeper/php-zookeeper/blob/master/examples/ Zookeeper_Example.php
위 내용은 PHP용 사육사 확장 프로그램을 설치하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

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

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

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

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

뜨거운 주제











최신 애플리케이션이 계속 발전하고 고가용성 및 동시성에 대한 요구가 증가함에 따라 분산 시스템 아키텍처가 점점 일반화되고 있습니다. 분산 시스템에서는 여러 프로세스 또는 노드가 동시에 실행되고 함께 작업을 완료하며 프로세스 간의 동기화가 특히 중요합니다. 분산 환경에서는 다수의 노드가 공유 자원에 동시에 접근할 수 있기 때문에 동시성 및 동기화 문제를 어떻게 처리하는가는 분산 시스템에서 중요한 작업이 되었습니다. 이런 점에서 ZooKeeper는 매우 인기 있는 솔루션이 되었습니다. 주키

인터넷의 급속한 발전으로 인해 분산 시스템은 많은 기업과 조직의 인프라 중 하나가 되었습니다. 분산 시스템이 제대로 작동하려면 조정 및 관리가 필요합니다. 이와 관련하여 ZooKeeper와 Curator는 사용할 가치가 있는 두 가지 도구입니다. ZooKeeper는 클러스터의 노드 간 상태와 데이터를 조정하는 데 도움이 되는 매우 인기 있는 분산 조정 서비스입니다. 큐레이터는 ZooKeeper를 캡슐화한 것입니다.

분산 잠금의 구현 방법에는 일반적으로 데이터베이스, 캐시(예: Redis), Zookeeper 등이 포함됩니다. 실제 개발에서는 Redis와 Zookeeper가 가장 일반적으로 사용되므로 이 기사에서는 이 두 가지에 대해서만 설명합니다.

PHP는 웹 애플리케이션 및 서버 측 개발에 널리 사용되는 매우 인기 있는 프로그래밍 언어입니다. Zookeeper는 분산 애플리케이션 및 서비스를 관리, 조정 및 모니터링하는 데 사용되는 분산 조정 서비스입니다. PHP 애플리케이션에서 Zookeeper를 사용하면 애플리케이션의 성능과 안정성을 향상시킬 수 있습니다. 이 기사에서는 PHP용 Zookeeper 확장 기능을 사용하는 방법을 소개합니다. 1. Zookeeper 확장을 설치합니다. Zookeeper 확장을 사용하려면 Zookeeper를 설치해야 합니다.

마이크로서비스 아키텍처에서 서비스 등록 및 검색은 매우 중요한 문제입니다. 이 문제를 해결하기 위해 ZooKeeper를 서비스 등록 센터로 사용할 수 있습니다. 이 기사에서는 Beego 프레임워크에서 ZooKeeper를 사용하여 서비스 등록 및 검색을 구현하는 방법을 소개합니다. 1. ZooKeeper 소개 ZooKeeper는 분산형 오픈소스 분산 조정 서비스로 Apache Hadoop의 하위 프로젝트 중 하나입니다. ZooKeeper의 주요 역할
![[추천컬렉션] 영혼의 고문! 사육사의 31발 대포](https://img.php.cn/upload/article/202308/28/2023082816453271532.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
ZooKeeper는 오픈 소스 분산 조정 서비스입니다. 분산 애플리케이션에 일관성 서비스를 제공하는 소프트웨어입니다. 분산 애플리케이션은 데이터 게시/구독, 로드 밸런싱, 이름 지정 서비스, 분산 조정/알림, 클러스터 관리, 마스터 선택, 분산 잠금 및 분산 대기열 및 기타 기능을 구현할 수 있습니다.

인터넷 기술의 급속한 발전으로 인해 분산 시스템은 현대 응용 프로그램, 특히 대규모 인터넷 회사에서 널리 사용되었습니다. 그러나 분산 시스템에서는 노드 간 일관성을 유지하는 것이 매우 어렵기 때문에 분산 잠금 메커니즘이 이 문제를 해결하기 위한 기반 중 하나가 되었습니다. 분산 잠금 구현에서 Redis와 ZooKeeper는 모두 널리 사용되는 도구입니다. 이 기사에서는 이를 비교하고 분석합니다. Redis는 분산 잠금을 구현합니다. Redis는 오픈 소스 메모리 데이터 저장소입니다.

dockerpullzookeeperdockerrun --namezk01-p2181:2181--restartalways-d2e30cac00aca는 Zookeeper가 Zookeeper 및 Dubbo를 성공적으로 시작했음을 나타냅니다. • ZooKeeperZooKeeper는 분산형 오픈 소스 분산 애플리케이션 조정 서비스입니다. 분산 애플리케이션에 일관된 서비스를 제공하는 소프트웨어입니다. 제공되는 기능에는 구성 유지 관리, 도메인 이름 서비스, 분산 동기화, 그룹 서비스 등이 있습니다. DubboDubbo는 Alibaba의 오픈소스 분산 서비스 프레임워크로, 계층적으로 구성되어 있다는 점이 가장 큰 특징입니다.
