浏览代码

Add multi curl

zjh 9 小时之前
父节点
当前提交
bf878621fd
共有 1 个文件被更改,包括 39 次插入0 次删除
  1. 39 0
      src/Library/LibMultiCurl.php

+ 39 - 0
src/Library/LibMultiCurl.php

@@ -0,0 +1,39 @@
+<?php
+namespace Qii\Library;
+/**
+ * A parallel HTTP client written in pure PHP
+ *
+ * This file just for non-composer user, require this file directly.
+ *
+ * @author hightman <hightman@twomice.net>
+ * @link http://hightman.cn
+ * @copyright Copyright (c) 2015 Twomice Studio.
+ */
+\Qii\Autoloader\Psr4::getInstance()
+    ->setUseNamespaces([
+        ['Curl', true],
+    ])
+    ->addNamespaces([
+        ['Curl', QII_DIR . DS .'Library'. DS . 'Third'. DS .'Curl'],
+    ]);
+use Curl\Curl;
+use Curl\MultiCurl;
+
+class LibMultiCurl extends MultiCurl
+{
+    /**
+     * 设置超时时间, 解决毫秒问题
+     *
+     * @param $seconds
+     */
+    public function setTimeout($seconds)
+    {
+        if($seconds < 1)
+        {
+            $this->setOpt(CURLOPT_TIMEOUT_MS, intval($seconds * 1000));
+            $this->setOpt(CURLOPT_NOSIGNAL, 1);
+        }
+
+        $this->setOpt(CURLOPT_TIMEOUT, $seconds);
+    }
+}