httprl.examples.php

  1. cis7 sites/all/modules/ulmus/httprl/examples/httprl.examples.php
  2. cle7 sites/all/modules/ulmus/httprl/examples/httprl.examples.php
  3. ecd7 sites/all/modules/ulmus/httprl/examples/httprl.examples.php
  4. elmsmedia7 sites/all/modules/ulmus/httprl/examples/httprl.examples.php
  5. harmony7 sites/all/modules/ulmus/httprl/examples/httprl.examples.php
  6. icor7 sites/all/modules/ulmus/httprl/examples/httprl.examples.php
  7. meedjum_blog7 sites/all/modules/ulmus/httprl/examples/httprl.examples.php
  8. mooc7 sites/all/modules/ulmus/httprl/examples/httprl.examples.php

HTTP Parallel Request Library code examples.

Functions

File

sites/all/modules/ulmus/httprl/examples/httprl.examples.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * HTTP Parallel Request Library code examples.
  5. */
  6. ?>
  7. **Simple HTTP**
  8. Request http://drupal.org/.
  9. <?php
  10. // Queue up the request.
  11. httprl_request('http://drupal.org/');
  12. // Execute request.
  13. $request = httprl_send_request();
  14. // Echo out the results.
  15. echo httprl_pr($request);
  16. ?>
  17. Request http://drupal.org/robots.txt and save it to tmp folder.
  18. <?php
  19. // Queue up the request.
  20. httprl_request('http://drupal.org/robots.txt');
  21. // Execute request.
  22. $request = httprl_send_request();
  23. // Save file if we got a 200 back.
  24. if ($request['http://drupal.org/robots.txt']->code == 200) {
  25. file_put_contents('/tmp/robots.txt', $request['http://drupal.org/robots.txt']->data);
  26. }
  27. ?>
  28. Request this servers own front page & the node page.
  29. <?php
  30. $options = array(
  31. 'headers' => array(
  32. // Set the Host header to self.
  33. 'Host' => $_SERVER['HTTP_HOST'],
  34. ),
  35. );
  36. // Build URL to point to front page of this server.
  37. $url_front = httprl_build_url_self();
  38. // Build URL to point to /node on this server.
  39. $url_node = httprl_build_url_self('node');
  40. // Queue up the requests.
  41. httprl_request($url_front, $options);
  42. httprl_request($url_node, $options);
  43. // Execute requests.
  44. $request = httprl_send_request();
  45. // Echo out the results.
  46. echo httprl_pr($request);
  47. ?>
  48. **Non Blocking HTTP Operations**
  49. Request 10 URLs in a non blocking manner on this server. Checkout watchdog as
  50. this should generate 10 404s and the $request object won't contain much info.
  51. <?php
  52. // Set the blocking mode.
  53. $options = array(
  54. 'blocking' => FALSE,
  55. 'headers' => array(
  56. // Set the Host header to self.
  57. 'Host' => $_SERVER['HTTP_HOST'],
  58. ),
  59. );
  60. // Queue up the requests.
  61. $max = 10;
  62. for ($i=1; $i <= $max; $i++) {
  63. // Build URL to a page that doesn't exist.
  64. $url = httprl_build_url_self('asdf-asdf-asdf-' . $i);
  65. httprl_request($url, $options);
  66. }
  67. // Execute requests.
  68. $request = httprl_send_request();
  69. // Echo out the results.
  70. echo httprl_pr($request);
  71. ?>
  72. Request 10 URLs in a non blocking manner with one httprl_request() call. These
  73. URLs will all have the same options.
  74. <?php
  75. // Set the blocking mode.
  76. $options = array(
  77. 'method' => 'HEAD',
  78. 'blocking' => FALSE,
  79. 'headers' => array(
  80. // Set the Host header to self.
  81. 'Host' => $_SERVER['HTTP_HOST'],
  82. ),
  83. );
  84. // Queue up the requests.
  85. $max = 10;
  86. $urls = array();
  87. for ($i=1; $i <= $max; $i++) {
  88. // Build URL to a page that doesn't exist.
  89. $urls[] = httprl_build_url_self('asdf-asdf-asdf-' . $i);
  90. }
  91. // Queue up the requests.
  92. httprl_request($urls, $options);
  93. // Execute requests.
  94. $request = httprl_send_request();
  95. // Echo out the results.
  96. echo httprl_pr($request);
  97. ?>
  98. Request 1000 URLs in a non blocking manner with one httprl_request() call. These
  99. URLs will all have the same options. This will saturate the server and any
  100. connections that couldn't be made will be dropped.
  101. <?php
  102. // Set the blocking mode.
  103. $options = array(
  104. 'method' => 'HEAD',
  105. 'blocking' => FALSE,
  106. 'domain_connections' => 1000,
  107. 'global_connections' => 1000,
  108. 'headers' => array(
  109. // Set the Host header to self.
  110. 'Host' => $_SERVER['HTTP_HOST'],
  111. ),
  112. );
  113. // Queue up the requests.
  114. $max = 1000;
  115. $urls = array();
  116. for ($i=1; $i <= $max; $i++) {
  117. // Build URL to a page that doesn't exist.
  118. $urls[] = httprl_build_url_self('asdf-asdf-asdf-' . $i);
  119. }
  120. // Queue up the requests.
  121. httprl_request($urls, $options);
  122. // Execute requests.
  123. $request = httprl_send_request();
  124. // Echo out the results.
  125. echo httprl_pr($request);
  126. ?>
  127. Request 1000 URLs in a non blocking manner with one httprl_request() call. These
  128. URLs will all have the same options. This will saturate the server. Usually all
  129. 1000 requests will eventually hit the server due to it waiting for the
  130. connection to be established; `async_connect` is FALSE.
  131. <?php
  132. // Set the blocking mode.
  133. $options = array(
  134. 'method' => 'HEAD',
  135. 'blocking' => FALSE,
  136. 'async_connect' => FALSE,
  137. // domain_connections must be smaller than the servers max number of
  138. // clients.
  139. 'domain_connections' => 32,
  140. 'global_connections' => 1000,
  141. 'headers' => array(
  142. // Set the Host header to self.
  143. 'Host' => $_SERVER['HTTP_HOST'],
  144. ),
  145. );
  146. // Queue up the requests.
  147. $max = 1000;
  148. $urls = array();
  149. for ($i=1; $i <= $max; $i++) {
  150. // Build URL to a page that doesn't exist.
  151. $urls[] = httprl_build_url_self('asdf-asdf-asdf-' . $i);
  152. }
  153. // Queue up the requests.
  154. httprl_request($urls, $options);
  155. // Execute requests.
  156. $request = httprl_send_request();
  157. // Echo out the results.
  158. echo httprl_pr($request);
  159. ?>
  160. **HTTP Operations and Callbacks**
  161. Use a callback in the event loop to do processing on the request. In this case
  162. we are going to use httprl_pr() as the callback function.
  163. <?php
  164. // Setup return variable.
  165. $x = '';
  166. // Setup options array.
  167. $options = array(
  168. 'method' => 'HEAD',
  169. 'callback' => array(
  170. array(
  171. 'function' => 'httprl_pr',
  172. 'return' => &$x,
  173. ),
  174. ),
  175. 'headers' => array(
  176. // Set the Host header to self.
  177. 'Host' => $_SERVER['HTTP_HOST'],
  178. ),
  179. );
  180. // Build URL to point to front page of this server.
  181. $url_front = httprl_build_url_self();
  182. // Queue up the request.
  183. httprl_request($url_front, $options);
  184. // Execute request.
  185. $request = httprl_send_request();
  186. // Echo returned value from function callback.
  187. echo $x;
  188. ?>
  189. Use a background callback in the event loop to do processing on the request.
  190. In this case we are going to use httprl_pr() as the callback function. A
  191. background callback creates a new thread to run this function in.
  192. <?php
  193. // Setup return variable.
  194. $x = '';
  195. // Setup options array.
  196. $options = array(
  197. 'method' => 'HEAD',
  198. 'background_callback' => array(
  199. array(
  200. 'function' => 'httprl_pr',
  201. 'return' => &$x,
  202. ),
  203. ),
  204. 'headers' => array(
  205. // Set the Host header to self.
  206. 'Host' => $_SERVER['HTTP_HOST'],
  207. ),
  208. );
  209. // Build URL to point to front page of this server.
  210. $url_front = httprl_build_url_self();
  211. // Queue up the request.
  212. httprl_request($url_front, $options);
  213. // Execute request.
  214. $request = httprl_send_request();
  215. // Echo returned value from function callback.
  216. echo $x;
  217. ?>
  218. Use a background callback in the event loop to do processing on the request.
  219. In this case we are going to use print_r() as the callback function. A
  220. background callback creates a new thread to run this function in. The first
  221. argument passed in is the request object, the FALSE tells print_r to echo out
  222. instead of returning a value.
  223. <?php
  224. // Setup return & print variable.
  225. $x = '';
  226. $y = '';
  227. // Setup options array.
  228. $options = array(
  229. 'method' => 'HEAD',
  230. 'background_callback' => array(
  231. array(
  232. 'function' => 'print_r',
  233. 'return' => &$x,
  234. 'printed' => &$y,
  235. ),
  236. FALSE,
  237. ),
  238. 'headers' => array(
  239. // Set the Host header to self.
  240. 'Host' => $_SERVER['HTTP_HOST'],
  241. ),
  242. );
  243. // Build URL to point to front page of this server.
  244. $url_front = httprl_build_url_self();
  245. // Queue up the request.
  246. httprl_request($url_front, $options);
  247. // Execute request.
  248. $request = httprl_send_request();
  249. // Echo what was returned and printed from function callback.
  250. echo $x . "<br />\n";
  251. echo $y;
  252. ?>
  253. **More Advanced HTTP Operations**
  254. Hit 5 different URLs, Using at least 2 that has a status code of 200 and
  255. erroring out the others that didn't return fast. Using the Range header so only
  256. the first and last 128 bytes are returned.
  257. <?php
  258. // Array of URLs to get.
  259. $urls = array(
  260. 'http://google.com/',
  261. 'http://bing.com/',
  262. 'http://yahoo.com/',
  263. 'http://www.duckduckgo.com/',
  264. 'http://www.drupal.org/',
  265. );
  266. // Process list of URLs.
  267. $options = array(
  268. 'alter_all_streams_function' => 'need_two_good_results',
  269. 'headers' => array('Range' => 'bytes=0-127,-128'),
  270. );
  271. // Queue up the requests.
  272. httprl_request($urls, $options);
  273. // Execute requests.
  274. $requests = httprl_send_request();
  275. // Print what was done.
  276. echo httprl_pr($requests);
  277. function need_two_good_results($id, &$responses) {
  278. static $counter = 0;
  279. foreach ($responses as $id => &$result) {
  280. // Skip if we got a 200 or 206.
  281. if ($result->code == 200 || $result->code == 206) {
  282. $counter += 1;
  283. continue;
  284. }
  285. if ($result->status == 'Done.') {
  286. continue;
  287. }
  288. if ($counter >= 2) {
  289. // Set the code to request was aborted.
  290. $result->code = HTTPRL_REQUEST_ABORTED;
  291. $result->error = 'Software caused connection abort.';
  292. // Set status to done and set timeout.
  293. $result->status = 'Done.';
  294. $result->options['timeout'] -= $result->running_time;
  295. // Close the file pointer and remove from the stream from the array.
  296. fclose($result->fp);
  297. unset($result->fp);
  298. }
  299. }
  300. }
  301. ?>
  302. Send 2 files in one field via a POST request.
  303. <?php
  304. // Set options.
  305. $options = array(
  306. 'method' => 'POST',
  307. 'data' => array(
  308. 'x' => 1,
  309. 'y' => 2,
  310. 'z' => 3,
  311. 'files' => array(
  312. 'core_js' => array(
  313. 'misc/form.js',
  314. 'misc/batch.js',
  315. ),
  316. ),
  317. ),
  318. 'headers' => array(
  319. // Set the Host header to self.
  320. 'Host' => $_SERVER['HTTP_HOST'],
  321. ),
  322. );
  323. // Send request to front page.
  324. $url_front = httprl_build_url_self();
  325. // Queue up the request.
  326. httprl_request($url_front, $options);
  327. // Execute request.
  328. $request = httprl_send_request();
  329. // Echo what was returned.
  330. echo httprl_pr($request);
  331. ?>
  332. Send out 8 requests. In this example we are going to stall the call to fread()
  333. `'stall_fread' => TRUE,`. By doing this we can issue a bunch of requests, do
  334. some other stuff and then get the results later on in the PHP process. A useful
  335. example would be for ESI emulation. Issue a bunch of requests at the start of
  336. the request, generate the main content and then add in the ESI-ed components at
  337. the end of the request.
  338. <?php
  339. // Queue up the request.
  340. $urls = array(
  341. 'http://www.google.com/',
  342. 'http://www.bing.com/',
  343. 'http://www.yahoo.com/',
  344. 'http://duckduckgo.com/',
  345. 'http://drupal.org/',
  346. 'http://drupal.org/robots.txt',
  347. 'http://drupal.org/CHANGELOG.txt',
  348. 'http://drupal.org/MAINTAINERS.txt',
  349. );
  350. $options = array(
  351. // Do fread in a second request.
  352. 'stall_fread' => TRUE,
  353. 'headers' => array(
  354. // Only grab the last 128 bytes of the request.
  355. 'Range' => 'bytes=-128',
  356. // Accept Compression.
  357. 'Accept-Encoding' => 'gzip, deflate',
  358. ),
  359. // Increase the read chunk size to 512KB.
  360. 'chunk_size_read' => 524288,
  361. // Increase domain_connections to 4 (drupal.org).
  362. 'domain_connections' => 4,
  363. // If we can't connect quick (0.5 seconds), bail out.
  364. 'connect_timeout' => 0.5,
  365. 'dns_timeout' => 0.5,
  366. );
  367. httprl_request($urls, $options);
  368. // Execute request.
  369. echo round(timer_read('page')/1000, 3) . " - Time taken to get requests ready.<br> \n";
  370. $request = httprl_send_request();
  371. echo strtoupper(var_export($request, TRUE)) . " - Output from first httprl_send_request() call<br> \n";
  372. echo round(timer_read('page')/1000, 3) . " - Time taken to send out all fwrites().<br> \n";
  373. sleep(2);
  374. echo round(timer_read('page')/1000, 3) . " - Time taken for sleep(2).<br> \n";
  375. $request = httprl_send_request();
  376. echo round(timer_read('page')/1000, 3) . " - Time taken for all freads().<br> \n";
  377. echo "Output from second httprl_send_request() below:<br> \n<br> \n";
  378. echo httprl_pr($request);
  379. ?>
  380. **Threading Examples**
  381. Use 2 threads to load up 4 different nodes.
  382. <?php
  383. // Bail out here if background callbacks are disabled.
  384. if (!httprl_is_background_callback_capable()) {
  385. return FALSE;
  386. }
  387. // List of nodes to load; 241-244.
  388. $nodes = array(241 => '', 242 => '', 243 => '', 244 => '');
  389. foreach ($nodes as $nid => &$node) {
  390. // Setup callback options array.
  391. $callback_options = array(
  392. array(
  393. 'function' => 'node_load',
  394. 'return' => &$node,
  395. // Setup options array.
  396. 'options' => array(
  397. 'domain_connections' => 2, // Only use 2 threads for this request.
  398. ),
  399. ),
  400. $nid,
  401. );
  402. // Queue up the request.
  403. httprl_queue_background_callback($callback_options);
  404. }
  405. // Execute request.
  406. httprl_send_request();
  407. // Echo what was returned.
  408. echo httprl_pr($nodes);
  409. ?>
  410. Load nodes 50-100 using httprl_batch_callback and node_load_multiple.
  411. <?php
  412. // List of nodes to load; 50-100.
  413. $nids = range(50, 100);
  414. // Run not parallel if background callbacks are disabled.
  415. if (!httprl_is_background_callback_capable()) {
  416. $results = node_load_multiple($nids);
  417. }
  418. else {
  419. // Queue & Execute requests.
  420. $results = httprl_batch_callback('node_load_multiple', $nids);
  421. }
  422. // Echo what was returned.
  423. echo httprl_pr($results);
  424. ?>
  425. Load nodes 50-100 using httprl_batch_callback and node_load.
  426. <?php
  427. // List of nodes to load; 50-100.
  428. $nids = range(50, 100);
  429. // Run not parallel if background callbacks are disabled.
  430. if (!httprl_is_background_callback_capable()) {
  431. // httprl_run_multiple does a foreach on $nids running every $value through
  432. // the given callback.
  433. $results = httprl_run_multiple('node_load', $nids);
  434. }
  435. else {
  436. // Set options.
  437. $options = array(
  438. 'multiple_helper' => TRUE,
  439. );
  440. // Queue & Execute requests.
  441. $results = httprl_batch_callback('node_load', $nids, $options);
  442. }
  443. // Echo what was returned.
  444. echo httprl_pr($results);
  445. ?>
  446. Load nodes 50-100 using httprl_batch_callback and node_load_multiple as user 1.
  447. <?php
  448. // List of nodes to load; 50-100.
  449. $nids = range(50, 100);
  450. // Run not parallel if background callbacks are disabled.
  451. if (!httprl_is_background_callback_capable()) {
  452. // Run node_load_multiple as user 1
  453. $current_account = $GLOBALS['user']->uid;
  454. $GLOBALS['user'] = user_load(1);
  455. $results = node_load_multiple($nids);
  456. // Set global user back.
  457. $GLOBALS['user'] = $current_account;
  458. }
  459. else {
  460. // Set options.
  461. $options = array(
  462. 'context' => array(
  463. 'uid' => 1,
  464. ),
  465. );
  466. // Queue & Execute requests.
  467. $results = httprl_batch_callback('node_load_multiple', $nids, $options);
  468. }
  469. // Echo what was returned.
  470. echo httprl_pr($results);
  471. ?>
  472. Run a function in the background. Notice that there is no return or printed key
  473. in the callback options.
  474. <?php
  475. // Bail out here if background callbacks are disabled.
  476. if (!httprl_is_background_callback_capable()) {
  477. return FALSE;
  478. }
  479. // Setup callback options array; call watchdog in the background.
  480. $callback_options = array(
  481. array(
  482. 'function' => 'watchdog',
  483. ),
  484. 'httprl-test', 'background watchdog call done', array(), WATCHDOG_DEBUG,
  485. );
  486. // Queue up the request.
  487. httprl_queue_background_callback($callback_options);
  488. // Execute request.
  489. httprl_send_request();
  490. ?>
  491. Pass by reference example. Example is D7 only; pass by reference works in
  492. D6 & D7.
  493. <?php
  494. // Code from system_rebuild_module_data().
  495. $modules = _system_rebuild_module_data();
  496. ksort($modules);
  497. // Show first module before running system_get_files_database().
  498. echo httprl_pr(current($modules));
  499. // Bail out here if background callbacks are disabled.
  500. if (!httprl_is_background_callback_capable()) {
  501. return FALSE;
  502. }
  503. $callback_options = array(
  504. array(
  505. 'function' => 'system_get_files_database',
  506. 'return' => '',
  507. ),
  508. &$modules, 'module'
  509. );
  510. httprl_queue_background_callback($callback_options);
  511. // Execute requests.
  512. httprl_send_request();
  513. // Show first module after running system_get_files_database().
  514. echo httprl_pr(current($modules));
  515. ?>
  516. Get 2 results from 2 different queries at the hook_boot bootstrap level in D6.
  517. <?php
  518. // Run 2 queries and get the result.
  519. $x = db_result(db_query_range("SELECT filename FROM {system} ORDER BY filename ASC", 0, 1));
  520. $y = db_result(db_query_range("SELECT filename FROM {system} ORDER BY filename DESC", 0, 1));
  521. echo $x . "<br \>\n" . $y . "<br \>\n";
  522. unset($x, $y);
  523. // Bail out here if background callbacks are disabled.
  524. if (!httprl_is_background_callback_capable()) {
  525. return FALSE;
  526. }
  527. // Run above 2 queries and get the result via a background callback.
  528. $args = array(
  529. // First query.
  530. array(
  531. 'type' => 'function',
  532. 'call' => 'db_query_range',
  533. 'args' => array('SELECT filename FROM {system} ORDER BY filename ASC', 0, 1),
  534. ),
  535. array(
  536. 'type' => 'function',
  537. 'call' => 'db_result',
  538. 'args' => array('last' => NULL),
  539. 'return' => &$x,
  540. ),
  541. // Second Query.
  542. array(
  543. 'type' => 'function',
  544. 'call' => 'db_query_range',
  545. 'args' => array('SELECT filename FROM {system} ORDER BY filename DESC', 0, 1),
  546. ),
  547. array(
  548. 'type' => 'function',
  549. 'call' => 'db_result',
  550. 'args' => array('last' => NULL),
  551. 'return' => &$y,
  552. ),
  553. );
  554. $callback_options = array(array('return' => ''), &$args);
  555. // Queue up the request.
  556. httprl_queue_background_callback($callback_options);
  557. // Execute request.
  558. httprl_send_request();
  559. // Echo what was returned.
  560. echo httprl_pr($x, $y);
  561. ?>
  562. Get 2 results from 2 different queries at the hook_boot bootstrap level in D7.
  563. <?php
  564. $x = db_select('system', 's')
  565. ->fields('s', array('filename'))
  566. ->orderBy('filename', 'ASC')
  567. ->range(0, 1)
  568. ->execute()
  569. ->fetchField();
  570. $y = db_select('system', 's')
  571. ->fields('s', array('filename'))
  572. ->orderBy('filename', 'DESC')
  573. ->range(0, 1)
  574. ->execute()
  575. ->fetchField();
  576. echo $x . "<br \>\n" . $y . "<br \>\n";
  577. unset($x, $y);
  578. // Bail out here if background callbacks are disabled.
  579. if (!httprl_is_background_callback_capable()) {
  580. return FALSE;
  581. }
  582. // Run above 2 queries and get the result via a background callback.
  583. $args = array(
  584. // First query.
  585. array(
  586. 'type' => 'function',
  587. 'call' => 'db_select',
  588. 'args' => array('system', 's',),
  589. ),
  590. array(
  591. 'type' => 'method',
  592. 'call' => 'fields',
  593. 'args' => array('s', array('filename')),
  594. ),
  595. array(
  596. 'type' => 'method',
  597. 'call' => 'orderBy',
  598. 'args' => array('filename', 'ASC'),
  599. ),
  600. array(
  601. 'type' => 'method',
  602. 'call' => 'range',
  603. 'args' => array(0, 1),
  604. ),
  605. array(
  606. 'type' => 'method',
  607. 'call' => 'execute',
  608. 'args' => array(),
  609. ),
  610. array(
  611. 'type' => 'method',
  612. 'call' => 'fetchField',
  613. 'args' => array(),
  614. 'return' => &$x,
  615. ),
  616. // Second Query.
  617. array(
  618. 'type' => 'function',
  619. 'call' => 'db_select',
  620. 'args' => array('system', 's',),
  621. ),
  622. array(
  623. 'type' => 'method',
  624. 'call' => 'fields',
  625. 'args' => array('s', array('filename')),
  626. ),
  627. array(
  628. 'type' => 'method',
  629. 'call' => 'orderBy',
  630. 'args' => array('filename', 'DESC'),
  631. ),
  632. array(
  633. 'type' => 'method',
  634. 'call' => 'range',
  635. 'args' => array(0, 1),
  636. ),
  637. array(
  638. 'type' => 'method',
  639. 'call' => 'execute',
  640. 'args' => array(),
  641. ),
  642. array(
  643. 'type' => 'method',
  644. 'call' => 'fetchField',
  645. 'args' => array(),
  646. 'return' => &$y,
  647. ),
  648. );
  649. $callback_options = array(array('return' => ''), &$args);
  650. // Queue up the request.
  651. httprl_queue_background_callback($callback_options);
  652. // Execute request.
  653. httprl_send_request();
  654. // Echo what was returned.
  655. echo httprl_pr($x, $y);
  656. ?>
  657. Run a cache clear at the DRUPAL_BOOTSTRAP_FULL level as the current user in a
  658. non blocking background request.
  659. <?php
  660. // Normal way to do this.
  661. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  662. module_load_include('inc', 'system', 'system.admin');
  663. system_clear_cache_submit();
  664. // Bail out here if background callbacks are disabled.
  665. if (!httprl_is_background_callback_capable()) {
  666. return FALSE;
  667. }
  668. // How to do it in a non blocking background request.
  669. $args = array(
  670. array(
  671. 'type' => 'function',
  672. 'call' => 'drupal_bootstrap',
  673. 'args' => array(DRUPAL_BOOTSTRAP_FULL),
  674. ),
  675. array(
  676. 'type' => 'function',
  677. 'call' => 'module_load_include',
  678. 'args' => array('inc', 'system', 'system.admin'),
  679. ),
  680. array(
  681. 'type' => 'function',
  682. 'call' => 'system_clear_cache_submit',
  683. 'args' => array('', ''),
  684. ),
  685. array(
  686. 'type' => 'function',
  687. 'call' => 'watchdog',
  688. 'args' => array('httprl-test', 'background cache clear done', array(), WATCHDOG_DEBUG),
  689. ),
  690. );
  691. // Pass the current session to the sub request.
  692. if (!empty($_COOKIE[session_name()])) {
  693. $options = array('headers' => array('Cookie' => session_name() . '=' . $_COOKIE[session_name()] . ';'));
  694. }
  695. else {
  696. $options = array();
  697. }
  698. $callback_options = array(array('options' => $options), &$args);
  699. // Queue up the request.
  700. httprl_queue_background_callback($callback_options);
  701. // Execute request.
  702. httprl_send_request();
  703. ?>
  704. print 'My Text'; cut the connection by sending the data over the wire and do
  705. processing in the background.
  706. <?php
  707. httprl_background_processing('My Text');
  708. // Everything after this point does not affect page load time.
  709. sleep(5);
  710. echo 'You should not see this text';
  711. ?>
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.