- enable $pool = new HttpRequestPool(HttpRequest r, ...);
authorMichael Wallner <mike@php.net>
Tue, 14 Jun 2005 15:40:39 +0000 (15:40 +0000)
committerMichael Wallner <mike@php.net>
Tue, 14 Jun 2005 15:40:39 +0000 (15:40 +0000)
http_methods.c
http_requestpool_object.c
php_http_std_defs.h

index f844c055ba06f3606be5a5281cfba399f771877b..1e454d83a3477dc884a98a07cb38bb0c48f6bfa2 100644 (file)
@@ -2142,13 +2142,46 @@ PHP_METHOD(HttpRequest, send)
 
 /* {{{ HttpRequestPool */
 
-/* {{{ proto void HttpRequestPool::__construct()
+/* {{{ proto void HttpRequestPool::__construct([HttpRequest request[, ...]])
  *
- * Instantiate a new HttpRequestPool object.
+ * Instantiate a new HttpRequestPool object.  An HttpRequestPool is
+ * able to send several HttpRequests in parallel.
+ *
+ * Example:
+ * <pre>
+ * <?php
+ *     $urls = array('www.php.net', 'pecl.php.net', 'pear.php.net')
+ *     $pool = new HttpRequestPool;
+ *     foreach ($urls as $url) {
+ *         $req[$url] = new HttpRequest("http://$url", HTTP_HEAD);
+ *         $pool->attach($req[$url]);
+ *     }
+ *     $pool->send();
+ *     foreach ($urls as $url) {
+ *         printf("%s (%s) is %s\n", 
+ *             $url, $req[$url]->getResponseInfo('effective_url'), 
+ *             $r->getResponseCode() == 200 ? 'alive' : 'not alive'
+ *         );
+ *     }
+ * ?>
+ * </pre>
  */
 PHP_METHOD(HttpRequestPool, __construct)
 {
-       NO_ARGS;
+       int argc = ZEND_NUM_ARGS();
+       zval ***argv = safe_emalloc(argc, sizeof(zval *), 0);
+       getObject(http_requestpool_object, obj);
+
+       if (SUCCESS == zend_get_parameters_array_ex(argc, argv)) {
+               int i;
+
+               for (i = 0; i < argc; ++i) {
+                       if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), http_request_object_ce TSRMLS_CC)) {
+                               http_request_pool_attach(&obj->pool, *(argv[i]));
+                       }
+               }
+       }
+       efree(argv);
 }
 /* }}} */
 
@@ -2162,7 +2195,7 @@ PHP_METHOD(HttpRequestPool, __destruct)
 
        NO_ARGS;
 
-       //http_request_pool_detach_all(&obj->pool);
+       http_request_pool_detach_all(&obj->pool);
 }
 /* }}} */
 
index 904fb9622c68a4bca9120329e2287761f9d6bfd8..f7161c7b0139e3ce887886a7e60d5fa44ccb24fb 100644 (file)
 #ifdef ZEND_ENGINE_2
 #ifdef HTTP_HAVE_CURL
 
+HTTP_DECLARE_ARG_PASS_INFO();
+
 #define http_requestpool_object_declare_default_properties() _http_requestpool_object_declare_default_properties(TSRMLS_C)
 static inline void _http_requestpool_object_declare_default_properties(TSRMLS_D);
 
 zend_class_entry *http_requestpool_object_ce;
 zend_function_entry http_requestpool_object_fe[] = {
-       PHP_ME(HttpRequestPool, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+       PHP_ME(HttpRequestPool, __construct, http_arg_pass_ref_all, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_ME(HttpRequestPool, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
        PHP_ME(HttpRequestPool, attach, NULL, ZEND_ACC_PUBLIC)
        PHP_ME(HttpRequestPool, detach, NULL, ZEND_ACC_PUBLIC)
index 87de9121f4140b9a63563ce563a8d1018c483459..00246859584ce7a7228f7010ed7613c57d770240 100644 (file)
@@ -271,12 +271,18 @@ typedef int STATUS;
                                ZEND_ARG_PASS_INFO(0) \
                                ZEND_ARG_PASS_INFO(0) \
                                ZEND_ARG_PASS_INFO(1) \
+                       ZEND_END_ARG_INFO(); \
+ \
+                       static \
+                       ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_all, 1) \
+                               ZEND_ARG_PASS_INFO(1) \
                        ZEND_END_ARG_INFO()
 #      else
 #              define HTTP_DECLARE_ARG_PASS_INFO() \
                        static unsigned char http_arg_pass_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
                        static unsigned char http_arg_pass_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
-                       static unsigned char http_arg_pass_ref_5[] = {5, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}
+                       static unsigned char http_arg_pass_ref_5[] = {5, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
+                       static unsigned char http_arg_pass_ref_all[]={1, BYREF_FORCE_REST}
 #      endif /* ZEND_ENGINE_2 */
 #else
 #      define HTTP_DECLARE_ARG_PASS_INFO()