最近要使用RabbitMQ 做消息队列,也是刚接触到.因为用的的TP框架,comoser又下载不下来,所以只能手动下载拓展包,做手动加载,在php-amqplib是我手动下载下来的拓展包,创建一个composer.json文件,在里面输入
1 { 2 "name": "php-amqplib/php-amqplib", 3 "replace": { 4 "videlalvaro/php-amqplib": "self.version" 5 }, 6 "type": "library", 7 "description": "Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.", 8 "keywords": ["rabbitmq", "message", "queue"], 9 "homepage": "https://github.com/php-amqplib/php-amqplib/", 10 "authors": [ 11 { 12 "name": "Alvaro Videla", 13 "role": "Original Maintainer" 14 }, 15 { 16 "name": "John Kelly", 17 "email": "johnmkelly86@gmail.com", 18 "role": "Maintainer" 19 }, 20 { 21 "name": "Raúl Araya", 22 "email": "nubeiro@gmail.com", 23 "role": "Maintainer" 24 } 25 ], 26 "require": { 27 "php": ">=5.3.0", 28 "ext-bcmath": "*", 29 "ext-mbstring": "*" 30 }, 31 "require-dev": { 32 "phpunit/phpunit": "^4.8", 33 "scrutinizer/ocular": "^1.1", 34 "squizlabs/php_codesniffer": "^2.5" 35 }, 36 "suggest": { 37 "ext-sockets": "Use AMQPSocketConnection" 38 }, 39 "autoload": { 40 "psr-4": { 41 "PhpAmqpLib\\": "php-amqplib/PhpAmqpLib/" //主要是这里,他是你加载包的路径,PhpAmqpLib 是空间命名,遵循的是PSR-4 自动加载原则 42 } 43 }, 44 "autoload-dev": { 45 "psr-4": { 46 "PhpAmqpLib\\Tests\\Functional\\": "tests/Functional", 47 "PhpAmqpLib\\Tests\\Unit\\": "tests/Unit" 48 } 49 }, 50 "license": "LGPL-2.1", 51 "extra": { 52 "branch-alias": { 53 "dev-master": "2.7-dev" 54 } 55 } 56 }
php composer.phar dump-autoload 就会生成一个vendor文件夹,使用的时候,你就只需把vendor文件夹里的autoload.php 文件引入进去就可以自动加载了