如何在全局安装PHP库?

时间:2018-01-27 17:46:03

标签: php include global php-7

我使用Apache在Mac High Sierra上运行PHP 7。如何安装库以便它可以普遍用于我的所有PHP脚本?我在test.php文件中有这一行

$loop = React\EventLoop\Factory::create();
$tcp = new \React\SocketClient\TcpConnector($loop);

有问题的源代码(来自ReactPHP - https://github.com/Bit-Wasp/stratum-php)位于目录中的单独项目中

./vendor/react/event-loop/src/Factory.php

我复制了" Factory.php"将文件归档到与我的" test.php"相同的目录文件,但我仍然得到错误

Fatal error: Uncaught Error: Class 'React\EventLoop\Factory' not found in /Library/WebServer/Documents/stratum/test.php on line 9

我可以在哪里安装丢失的文件,以便所有脚本可以普遍使用它?

编辑:我曾尝试使用composer安装库。以下是输出。我不知道它在哪里安装东西,但我的代码却没有把它拿走......

localhost:react-master davea$ composer global require react/event-loop react/http
Changed current directory to /Users/davea/.composer
Using version ^0.4.3 for react/event-loop
Using version ^0.8.1 for react/http
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 0 updates, 0 removals
  - Installing react/promise (v2.5.1): Loading from cache
  - Installing evenement/evenement (v3.0.1): Downloading (100%)
  - Installing react/event-loop (v0.4.3): Loading from cache
  - Installing react/stream (v0.7.7): Loading from cache
  - Installing react/promise-stream (v1.1.1): Loading from cache
  - Installing react/promise-timer (v1.2.1): Loading from cache
  - Installing react/socket (v0.8.9): Loading from cache
  - Installing react/dns (v0.4.12): Loading from cache
  - Installing react/cache (v0.4.2): Loading from cache
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing ringcentral/psr7 (1.2.2): Loading from cache
  - Installing react/http (v0.8.1): Loading from cache
react/event-loop suggests installing ext-libevent (>=0.1.0)
react/event-loop suggests installing ext-event (~1.0)
react/event-loop suggests installing ext-libev (*)
Writing lock file
Generating autoload files

0 个答案:

没有答案