YII使用beanstalk队列

转载于:http://blog.csdn.net/yao970953039/article/details/41821387

1.系统centos 我是直接使用yum install beanstalk安装的

2.下载beanstalk的php扩展包 放在extensions

[php] view plaincopy

  1. //控制器往队列里面塞任务  @author yao
  2. Yii::import(‘application.extensions.SendSmsBeanstalk‘);
  3. class AController extends CController{
  4. public function actionIndex(){
  5. for($i=0;$i<1000;$i++){
  6. SendSmsBeanstalk::sendSms(‘sendsms_‘.$i);
  7. }
  8. }
  9. public function actionA(){
  10. SendSmsBeanstalk::handleMessage();
  11. }
  12. }

[php] view plaincopy

  1. </pre><pre code_snippet_id="546591" snippet_file_name="blog_20141209_4_7698245" name="code" class="php">//发送短信  @author yao
  2. Yii::import(‘application.extensions.beanstalk.*‘);
  3. class SendSmsBeanstalk extends CComponent{
  4. //建立发短信任务
  5. public static function sendSms($body){
  6. //实例化beanstalk
  7. $beanstalk = new Socket_Beanstalk();
  8. if (!$beanstalk->connect()) {
  9. exit(current($beanstalk->errors()));
  10. }
  11. //选择使用的tube
  12. $beanstalk->useTube(‘hube_send_smss‘);
  13. //往tube中增加数据
  14. $put = $beanstalk->put(
  15. 23, // 任务的优先级.
  16. 0, // 不等待直接放到ready队列中.
  17. 60, // 处理任务的时间.
  18. $body // 任务内容
  19. );
  20. if (!$put) {
  21. return false;
  22. }
  23. $beanstalk->disconnect();
  24. }
  25. //处理消息
  26. public static function handleMessage(){
  27. //实例化beanstalk
  28. $beanstalk = new Socket_Beanstalk();
  29. if (!$beanstalk->connect()) {
  30. exit(current($beanstalk->errors()));
  31. }
  32. $beanstalk->useTube(‘hube_send_smss‘);
  33. //设置要监听的tube
  34. $beanstalk->watch(‘hube_send_smss‘);
  35. //取消对默认tube的监听,可以省略
  36. $beanstalk->ignore(‘default‘);
  37. while($job = $beanstalk->reserve(2)){//这里我写了单个任务只执行2秒。防止超时。本地测试的时候 没写超时会一直执行下去,哪怕队列里面已经没有任务
  38. //处理任务
  39. $result = $job[‘body‘];
  40. echo $job[‘id‘];echo ‘<br>‘;//打印任务ID
  41. if ($result) {<span style="font-family: Arial, Helvetica, sans-serif;">//这里可以写逻辑 todo</span>

[php] view plaincopy

  1. //删除任务
  2. $beanstalk->delete($job[‘id‘]);
  3. } else {
  4. //休眠任务
  5. $beanstalk->bury($job[‘id‘],‘‘);
  6. }
  7. }
  8. $beanstalk->disconnect();
  9. }

下方提供我找到的队列PHP版本core,不能上传附件。代码在下面

[php] view plaincopy

  1. /**
  2. * beanstalk: A minimalistic PHP beanstalk client.
  3. *
  4. * Copyright (c) 2009-2012 David Persson
  5. *
  6. * Distributed under the terms of the MIT License.
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright  2009-2012 David Persson <[email protected]>
  10. * @license    http://www.opensource.org/licenses/mit-license.php The MIT License
  11. * @link       http://github.com/davidpersson/beanstalk
  12. */
  13. /**
  14. * An interface to the beanstalk queue service. Implements the beanstalk
  15. * protocol spec 1.2. Where appropriate the documentation from the protcol has
  16. * been added to the docblocks in this class.
  17. *
  18. * @link https://github.com/kr/beanstalkd/blob/master/doc/protocol.txt
  19. */
  20. class Socket_Beanstalk {
  21. /**
  22. * Holds a boolean indicating whether a connection to the server is
  23. * currently established or not.
  24. *
  25. * @var boolean
  26. */
  27. public $connected = false;
  28. /**
  29. * Holds configuration values.
  30. *
  31. * @var array
  32. */
  33. protected $_config = array();
  34. /**
  35. * The current connection resource handle (if any).
  36. *
  37. * @var resource
  38. */
  39. protected $_connection;
  40. /**
  41. * Generated errors. Will hold a maximum of 200 error messages at any time
  42. * to prevent pilling up messages and using more and more memory. This is
  43. * especially important if this class is used in long-running workers.
  44. *
  45. * @see Socket_Beanstalk::errors()
  46. * @see Socket_Beanstalk::_error()
  47. * @var array
  48. */
  49. protected $_errors = array();
  50. /**
  51. * Constructor.
  52. *
  53. * @param array $config An array of configuration values:
  54. *        - `‘persistent‘`  Whether to make the connection persistent or
  55. *                          not, defaults to `true` as the FAQ recommends
  56. *                          persistent connections.
  57. *        - `‘host‘`        The beanstalk server hostname or IP address to
  58. *                          connect to, defaults to `127.0.0.1`.
  59. *        - `‘port‘`        The port of the server to connect to, defaults
  60. *                          to `11300`.
  61. *        - `‘timeout‘`     Timeout in seconds when establishing the
  62. *                          connection, defaults to `1`.
  63. * @return void
  64. */
  65. public function __construct(array $config = array()) {
  66. $defaults = array(
  67. ‘persistent‘ => true,
  68. ‘host‘ => ‘127.0.0.1‘,
  69. ‘port‘ => 11300,
  70. ‘timeout‘ => 1
  71. );
  72. $this->_config = $config + $defaults;
  73. }
  74. /**
  75. * Destructor, disconnects from the server.
  76. *
  77. * @return void
  78. */
  79. public function __destruct() {
  80. $this->disconnect();
  81. }
  82. /**
  83. * Initiates a socket connection to the beanstalk server. The resulting
  84. * stream will not have any timeout set on it. Which means it can wait an
  85. * unlimited amount of time until a packet becomes available. This is
  86. * required for doing blocking reads.
  87. *
  88. * @see Socket_Beanstalk::$_connection
  89. * @see Socket_Beanstalk::reserve()
  90. * @return boolean `true` if the connection was established, `false` otherwise.
  91. */
  92. public function connect() {
  93. if (isset($this->_connection)) {
  94. $this->disconnect();
  95. }
  96. $function = $this->_config[‘persistent‘] ? ‘pfsockopen‘ : ‘fsockopen‘;
  97. $params = array($this->_config[‘host‘], $this->_config[‘port‘], &$errNum, &$errStr);
  98. if ($this->_config[‘timeout‘]) {
  99. $params[] = $this->_config[‘timeout‘];
  100. }
  101. $this->_connection = @call_user_func_array($function, $params);
  102. if (!empty($errNum) || !empty($errStr)) {
  103. $this->_error("{$errNum}: {$errStr}");
  104. }
  105. $this->connected = is_resource($this->_connection);
  106. if ($this->connected) {
  107. stream_set_timeout($this->_connection, -1);
  108. }
  109. return $this->connected;
  110. }
  111. /**
  112. * Closes the connection to the beanstalk server.
  113. *
  114. * @return boolean `true` if diconnecting was successful.
  115. */
  116. public function disconnect() {
  117. if (!is_resource($this->_connection)) {
  118. $this->connected = false;
  119. } else {
  120. $this->connected = !fclose($this->_connection);
  121. if (!$this->connected) {
  122. $this->_connection = null;
  123. }
  124. }
  125. return !$this->connected;
  126. }
  127. /**
  128. * Returns collected error messages.
  129. *
  130. * @return array An array of error messages.
  131. */
  132. public function errors() {
  133. return $this->_errors;
  134. }
  135. /**
  136. * Pushes an error message to `Beanstalk::$_errors`. Ensures
  137. * that at any point there are not more than 200 messages.
  138. *
  139. * @param string $message The error message.
  140. * @return void
  141. */
  142. protected function _error($message) {
  143. if (count($this->_errors) >= 200) {
  144. array_shift($this->_errors);
  145. }
  146. array_push($this->_errors, $message);
  147. }
  148. /**
  149. * Writes a packet to the socket. Prior to writing to the socket will check
  150. * for availability of the connection.
  151. *
  152. * @param string $data
  153. * @return integer|boolean number of written bytes or `false` on error.
  154. */
  155. protected function _write($data) {
  156. if (!$this->connected && !$this->connect()) {
  157. return false;
  158. }
  159. $data .= "\r\n";
  160. return fwrite($this->_connection, $data, strlen($data));
  161. }
  162. /**
  163. * Reads a packet from the socket. Prior to reading from the socket will
  164. * check for availability of the connection.
  165. *
  166. * @param int $length Number of bytes to read.
  167. * @return string|boolean Data or `false` on error.
  168. */
  169. protected function _read($length = null) {
  170. if (!$this->connected && !$this->connect()) {
  171. return false;
  172. }
  173. if ($length) {
  174. if (feof($this->_connection)) {
  175. return false;
  176. }
  177. $data = fread($this->_connection, $length + 2);
  178. $meta = stream_get_meta_data($this->_connection);
  179. if ($meta[‘timed_out‘]) {
  180. $this->_error(‘Connection timed out.‘);
  181. return false;
  182. }
  183. $packet = rtrim($data, "\r\n");
  184. } else {
  185. $packet = stream_get_line($this->_connection, 16384, "\r\n");
  186. }
  187. return $packet;
  188. }
  189. /* Producer Commands */
  190. /**
  191. * The `put` command is for any process that wants to insert a job into the queue.
  192. *
  193. * @param integer $pri Jobs with smaller priority values will be scheduled
  194. *        before jobs with larger priorities. The most urgent priority is
  195. *        0; the least urgent priority is 4294967295.
  196. * @param integer $delay Seconds to wait before putting the job in the
  197. *        ready queue.  The job will be in the "delayed" state during this time.
  198. * @param integer $ttr Time to run - Number of seconds to allow a worker to
  199. *        run this job.  The minimum ttr is 1.
  200. * @param string $data The job body.
  201. * @return integer|boolean `false` on error otherwise an integer indicating
  202. *         the job id.
  203. */
  204. public function put($pri, $delay, $ttr, $data) {
  205. $this->_write(sprintf(‘put %d %d %d %d‘, $pri, $delay, $ttr, strlen($data)));
  206. $this->_write($data);
  207. $status = strtok($this->_read(), ‘ ‘);
  208. switch ($status) {
  209. case ‘INSERTED‘:
  210. case ‘BURIED‘:
  211. return (integer)strtok(‘ ‘); // job id
  212. case ‘EXPECTED_CRLF‘:
  213. case ‘JOB_TOO_BIG‘:
  214. default:
  215. $this->_error($status);
  216. return false;
  217. }
  218. }
  219. /**
  220. * The `use` command is for producers. Subsequent put commands will put jobs into
  221. * the tube specified by this command. If no use command has been issued, jobs
  222. * will be put into the tube named `default`.
  223. *
  224. * Please note that while obviously this method should better be named
  225. * `use` it is not. This is because `use` is a reserved keyword in PHP.
  226. *
  227. * @param string $tube A name at most 200 bytes. It specifies the tube to
  228. *        use.  If the tube does not exist, it will be created.
  229. * @return string|boolean `false` on error otherwise the name of the tube.
  230. */
  231. public function choose($tube) {
  232. $this->_write(sprintf(‘use %s‘, $tube));
  233. $status = strtok($this->_read(), ‘ ‘);
  234. switch ($status) {
  235. case ‘USING‘:
  236. return strtok(‘ ‘);
  237. default:
  238. $this->_error($status);
  239. return false;
  240. }
  241. }
  242. /**
  243. * Alias for choose.
  244. *
  245. * @see Socket_Beanstalk::choose()
  246. * @param string $tube
  247. * @return string|boolean
  248. */
  249. public function useTube($tube) {
  250. return $this->choose($tube);
  251. }
  252. /* Worker Commands */
  253. /**
  254. * Reserve a job (with a timeout)
  255. *
  256. * @param integer $timeout If given specifies number of seconds to wait for
  257. *        a job. 0 returns immediately.
  258. * @return array|false `false` on error otherwise an array holding job id
  259. *         and body.
  260. */
  261. public function reserve($timeout = null) {
  262. if (isset($timeout)) {
  263. $this->_write(sprintf(‘reserve-with-timeout %d‘, $timeout));
  264. } else {
  265. $this->_write(‘reserve‘);
  266. }
  267. $status = strtok($this->_read(), ‘ ‘);
  268. switch ($status) {
  269. case ‘RESERVED‘:
  270. return array(
  271. ‘id‘ => (integer)strtok(‘ ‘),
  272. ‘body‘ => $this->_read((integer)strtok(‘ ‘))
  273. );
  274. case ‘DEADLINE_SOON‘:
  275. case ‘TIMED_OUT‘:
  276. default:
  277. $this->_error($status);
  278. return false;
  279. }
  280. }
  281. /**
  282. * Removes a job from the server entirely.
  283. *
  284. * @param integer $id The id of the job.
  285. * @return boolean `false` on error, `true` on success.
  286. */
  287. public function delete($id) {
  288. $this->_write(sprintf(‘delete %d‘, $id));
  289. $status = $this->_read();
  290. switch ($status) {
  291. case ‘DELETED‘:
  292. return true;
  293. case ‘NOT_FOUND‘:
  294. default:
  295. $this->_error($status);
  296. return false;
  297. }
  298. }
  299. /**
  300. * Puts a reserved job back into the ready queue.
  301. *
  302. * @param integer $id The id of the job.
  303. * @param integer $pri Priority to assign to the job.
  304. * @param integer $delay Number of seconds to wait before putting the job in the ready queue.
  305. * @return boolean `false` on error, `true` on success.
  306. */
  307. public function release($id, $pri, $delay) {
  308. $this->_write(sprintf(‘release %d %d %d‘, $id, $pri, $delay));
  309. $status = $this->_read();
  310. switch ($status) {
  311. case ‘RELEASED‘:
  312. case ‘BURIED‘:
  313. return true;
  314. case ‘NOT_FOUND‘:
  315. default:
  316. $this->_error($status);
  317. return false;
  318. }
  319. }
  320. /**
  321. * Puts a job into the `buried` state Buried jobs are put into a FIFO
  322. * linked list and will not be touched until a client kicks them.
  323. *
  324. * @param integer $id The id of the job.
  325. * @param integer $pri *New* priority to assign to the job.
  326. * @return boolean `false` on error, `true` on success.
  327. */
  328. public function bury($id, $pri) {
  329. $this->_write(sprintf(‘bury %d %d‘, $id, $pri));
  330. $status = $this->_read();
  331. switch ($status) {
  332. case ‘BURIED‘:
  333. return true;
  334. case ‘NOT_FOUND‘:
  335. default:
  336. $this->_error($status);
  337. return false;
  338. }
  339. }
  340. /**
  341. * Allows a worker to request more time to work on a job
  342. *
  343. * @param integer $id The id of the job.
  344. * @return boolean `false` on error, `true` on success.
  345. */
  346. public function touch($id) {
  347. $this->_write(sprintf(‘touch %d‘, $id));
  348. $status = $this->_read();
  349. switch ($status) {
  350. case ‘TOUCHED‘:
  351. return true;
  352. case ‘NOT_TOUCHED‘:
  353. default:
  354. $this->_error($status);
  355. return false;
  356. }
  357. }
  358. /**
  359. * Adds the named tube to the watch list for the current
  360. * connection.
  361. *
  362. * @param string $tube Name of tube to watch.
  363. * @return integer|boolean `false` on error otherwise number of tubes in watch list.
  364. */
  365. public function watch($tube) {
  366. $this->_write(sprintf(‘watch %s‘, $tube));
  367. $status = strtok($this->_read(), ‘ ‘);
  368. switch ($status) {
  369. case ‘WATCHING‘:
  370. return (integer)strtok(‘ ‘);
  371. default:
  372. $this->_error($status);
  373. return false;
  374. }
  375. }
  376. /**
  377. * Remove the named tube from the watch list.
  378. *
  379. * @param string $tube Name of tube to ignore.
  380. * @return integer|boolean `false` on error otherwise number of tubes in watch list.
  381. */
  382. public function ignore($tube) {
  383. $this->_write(sprintf(‘ignore %s‘, $tube));
  384. $status = strtok($this->_read(), ‘ ‘);
  385. switch ($status) {
  386. case ‘WATCHING‘:
  387. return (integer)strtok(‘ ‘);
  388. case ‘NOT_IGNORED‘:
  389. default:
  390. $this->_error($status);
  391. return false;
  392. }
  393. }
  394. /* Other Commands */
  395. /**
  396. * Inspect a job by its id.
  397. *
  398. * @param integer $id The id of the job.
  399. * @return string|boolean `false` on error otherwise the body of the job.
  400. */
  401. public function peek($id) {
  402. $this->_write(sprintf(‘peek %d‘, $id));
  403. return $this->_peekRead();
  404. }
  405. /**
  406. * Inspect the next ready job.
  407. *
  408. * @return string|boolean `false` on error otherwise the body of the job.
  409. */
  410. public function peekReady() {
  411. $this->_write(‘peek-ready‘);
  412. return $this->_peekRead();
  413. }
  414. /**
  415. * Inspect the job with the shortest delay left.
  416. *
  417. * @return string|boolean `false` on error otherwise the body of the job.
  418. */
  419. public function peekDelayed() {
  420. $this->_write(‘peek-delayed‘);
  421. return $this->_peekRead();
  422. }
  423. /**
  424. * Inspect the next job in the list of buried jobs.
  425. *
  426. * @return string|boolean `false` on error otherwise the body of the job.
  427. */
  428. public function peekBuried() {
  429. $this->_write(‘peek-buried‘);
  430. return $this->_peekRead();
  431. }
  432. /**
  433. * Handles response for all peek methods.
  434. *
  435. * @return string|boolean `false` on error otherwise the body of the job.
  436. */
  437. protected function _peekRead() {
  438. $status = strtok($this->_read(), ‘ ‘);
  439. switch ($status) {
  440. case ‘FOUND‘:
  441. return array(
  442. ‘id‘ => (integer)strtok(‘ ‘),
  443. ‘body‘ => $this->_read((integer)strtok(‘ ‘))
  444. );
  445. case ‘NOT_FOUND‘:
  446. default:
  447. $this->_error($status);
  448. return false;
  449. }
  450. }
  451. /**
  452. * Moves jobs into the ready queue (applies to the current tube).
  453. *
  454. * If there are buried jobs those get kicked only otherwise
  455. * delayed jobs get kicked.
  456. *
  457. * @param integer $bound Upper bound on the number of jobs to kick.
  458. * @return integer|boolean False on error otherwise number of job kicked.
  459. */
  460. public function kick($bound) {
  461. $this->_write(sprintf(‘kick %d‘, $bound));
  462. $status = strtok($this->_read(), ‘ ‘);
  463. switch ($status) {
  464. case ‘KICKED‘:
  465. return (integer)strtok(‘ ‘);
  466. default:
  467. $this->_error($status);
  468. return false;
  469. }
  470. }
  471. /* Stats Commands */
  472. /**
  473. * Gives statistical information about the specified job if it exists.
  474. *
  475. * @param integer $id The job id
  476. * @return string|boolean `false` on error otherwise a string with a yaml formatted dictionary
  477. */
  478. public function statsJob($id) {
  479. $this->_write(sprintf(‘stats-job %d‘, $id));
  480. return $this->_statsRead();
  481. }
  482. /**
  483. * Gives statistical information about the specified tube if it exists.
  484. *
  485. * @param string $tube Name of the tube.
  486. * @return string|boolean `false` on error otherwise a string with a yaml formatted dictionary.
  487. */
  488. public function statsTube($tube) {
  489. $this->_write(sprintf(‘stats-tube %s‘, $tube));
  490. return $this->_statsRead();
  491. }
  492. /**
  493. * Gives statistical information about the system as a whole.
  494. *
  495. * @return string|boolean `false` on error otherwise a string with a yaml formatted dictionary.
  496. */
  497. public function stats() {
  498. $this->_write(‘stats‘);
  499. return $this->_statsRead();
  500. }
  501. /**
  502. * Returns a list of all existing tubes.
  503. *
  504. * @return string|boolean `false` on error otherwise a string with a yaml formatted list.
  505. */
  506. public function listTubes() {
  507. $this->_write(‘list-tubes‘);
  508. return $this->_statsRead();
  509. }
  510. /**
  511. * Returns the tube currently being used by the producer.
  512. *
  513. * @return string|boolean `false` on error otherwise a string with the name of the tube.
  514. */
  515. public function listTubeUsed() {
  516. $this->_write(‘list-tube-used‘);
  517. $status = strtok($this->_read(), ‘ ‘);
  518. switch ($status) {
  519. case ‘USING‘:
  520. return strtok(‘ ‘);
  521. default:
  522. $this->_error($status);
  523. return false;
  524. }
  525. }
  526. /**
  527. * Alias for listTubeUsed.
  528. *
  529. * @see Socket_Beanstalk::listTubeUsed()
  530. * @return string|boolean `false` on error otherwise a string with the name of the tube.
  531. */
  532. public function listTubeChosen() {
  533. return $this->listTubeUsed();
  534. }
  535. /**
  536. * Returns a list of tubes currently being watched by the worker.
  537. *
  538. * @return string|boolean `false` on error otherwise a string with a yaml formatted list.
  539. */
  540. public function listTubesWatched() {
  541. $this->_write(‘list-tubes-watched‘);
  542. return $this->_statsRead();
  543. }
  544. /**
  545. * Handles responses for all stat methods.
  546. *
  547. * @param boolean $decode Whether to decode data before returning it or not. Default is `true`.
  548. * @return array|string|boolean `false` on error otherwise statistical data.
  549. */
  550. protected function _statsRead($decode = true) {
  551. $status = strtok($this->_read(), ‘ ‘);
  552. switch ($status) {
  553. case ‘OK‘:
  554. $data = $this->_read((integer)strtok(‘ ‘));
  555. return $decode ? $this->_decode($data) : $data;
  556. default:
  557. $this->_error($status);
  558. return false;
  559. }
  560. }
  561. /**
  562. * Decodes YAML data. This is a super naive decoder which just works on a
  563. * subset of YAML which is commonly returned by beanstalk.
  564. *
  565. * @param string $data The data in YAML format, can be either a list or a dictionary.
  566. * @return array An (associative) array of the converted data.
  567. */
  568. protected function _decode($data) {
  569. $data = array_slice(explode("\n", $data), 1);
  570. $result = array();
  571. foreach ($data as $key => $value) {
  572. if ($value[0] === ‘-‘) {
  573. $value = ltrim($value, ‘- ‘);
  574. } elseif (strpos($value, ‘:‘) !== false) {
  575. list($key, $value) = explode(‘:‘, $value);
  576. $value = ltrim($value, ‘ ‘);
  577. }
  578. if (is_numeric($value)) {
  579. $value = (integer) $value == $value ? (integer) $value : (float) $value;
  580. }
  581. $result[$key] = $value;
  582. }
  583. return $result;
  584. }
  585. }

安装成功是上面这样子

时间: 2024-08-30 12:29:00

YII使用beanstalk队列的相关文章

Yii2 使用 Beanstalk 队列系统

参考网址: Beanstalk:https://github.com/kr/beanstalkd Beanstalk console:https://github.com/ptrofimov/beanstalk_console Yii2-beanstalk:http://www.te.gd/extension/yii2-beanstalk/ 中文文档出来了:https://github.com/kr/beanstalkd/blob/master/doc/protocol.zh-CN.md

acl 网络通信与服务器框架库示例列表

跨平台网络通信及服务器框架库 --- "acl" 项目里有大量的测试及应用示例,主要有三个示例集合,如下: 1.acl/samples:该目录下的例子主要是基于 lib_acl 及 lib_protocol 两个库的例子-    1.1 acl: 打印当前 acl 库版本号程序-    1.2 aio/client: 非阻塞 io 客户端-    1.3 aio/server: 非阻塞 io 服务器-    1.4 base64: base64 编/解码程序-    1.5 btree

(转)yii流程,入口文件下的准备工作

yii流程 一 目录文件 |-framework     框架核心库 |--base         底层类库文件夹,包含CApplication(应用类,负责全局的用户请求处理,它管理的应用组件集,将提供特定功能给整个应用程 序),CComponent(组件类,该文件包含了基于组件和事件驱动编程的基础类,从版本1.1.0开始,一个行为的属性(或者它的公共成员变量或它通 过getter和/或setter方法??定义的属性)可以通过组件的访问来调用),CBehavior(行为类,主要负责声明事件和

yii执行流程

yii执行流程 原文:http://www.cnblogs.com/bluecobra/archive/2011/11/30/2269207.html 一 目录文件 |-framework     框架核心库 |--base         底层类库文件夹,包含CApplication(应用类,负责全局的用户请求处理,它管理的应用组件集,将提供特定功能给整个应用程序),CComponent(组件类,该文件包含了基于组件和事件驱动编程的基础类,从版本1.1.0开始,一个行为的属性(或者它的公共成员

yii开发第一部分之执行流程

一 目录文件 |-framework 框架核心库 |--base 底层类库文件夹,包含CApplication(应用类,负责全局的用户请求处理,它管理的应用组件集,将提供特定功能给整个应用程序),CComponent(组件类,该文件包含了基于组件和事件驱动编程的基础类,从版本1.1.0开始,一个行为的属性(或者它的公共成员变量或它通过getter和/或setter方法??定义的属性)可以通过组件的访问来调用),CBehavior(行为类,主要负责声明事件和相应事件处理程序的方法.将对象的行为附加

Yii框架分析(二)——CComponent类剖析

Yii是基于组件(component-based)的web框架,CComponent类是所有组件的基类. CComponent类为子类提供了基于属性(property).事件(event).行为(behavior)编程接口. 1.组件的属性(property) Ccomponent类并没有提供属性的变量存储,需要由子类来提供两个方法来实现.子类的getPropertyName()方法提供$component->PropertyName的取值操作数据,子类的setPropertyName($val

Yii -- framework 目录结构说明

base 底层的类库文件 caching 所有缓存方法 cli 项目生成脚本 collecions 用PHP语言构造传统OO语言的数据存储单元.如队列,栈,哈希等等 console yii控制台 db数据库操作类 gii代码生成器(脚手架,可以生成模型.控制器.视图等代码) i18n 多语言 logging 日志组件 test Yii提供的测试,包括单元测试和功能测试 utils 提供了常用的格式化方法 validators 提供了各种验证方法 vendors 这个文件夹包括第三方由YII框架使

轻量级队列beanstalkd

一.基本Beanstalkd,一个高性能.轻量级的分布式内存队列系统,最初设计的目的是想通过后台异步执行耗时的任务来降低高容量Web应用系统的页面访问延迟,支持过有9.5 million用户的Facebook Causes应用.后来开源,现在有PostRank大规模部署和使用,每天处理百万级任务.Beanstalkd是典型的类Memcached设计,协议和使用方式都是同样的风格,所以使用过memcached的用户会觉得Beanstalkd似曾相识. 二.服务端1.https://github.c

yii2.0 中的队列

a yii2 extension to make simple to use queue. yii2-queue让队列的使用在yii2中变得更轻松,她为各种队列组件的使用提供了一个标准的接口,您只需要配置好需要使用的队列组件,就能轻松使用,同时您在不同队列组件之间的切换也只需要修改下配置文件,重启下队列监听进程即可,目前支持数据库队列,redis队列,beanstalkd队列,其它队列中间件支持正在添加中(当然,聪明的你也可以自行扩展). Installation The preferred w