Annotation of embedaddon/php/ext/curl/tests/curl_basic_006.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test curl_opt() function with CURLOPT_WRITEFUNCTION parameter set to a closure
                      3: --CREDITS--
                      4: ?
                      5: TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net>
                      6: --SKIPIF--
                      7: <?php 
                      8: if (!extension_loaded("curl")) exit("skip curl extension not loaded");
                      9: if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER'))  exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined");
                     10: ?>
                     11: --FILE--
                     12: <?php
                     13: /* Prototype  : bool curl_setopt(resource ch, int option, mixed value)
                     14:  * Description: Set an option for a cURL transfer
                     15:  * Source code: ext/curl/interface.c
                     16:  * Alias to functions:
                     17:  */
                     18: 
                     19:   $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
                     20: 
                     21:   // start testing
                     22:   echo '*** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***' . "\n";
                     23: 
                     24:   $url = "{$host}/get.php?test=get";
                     25:   $ch = curl_init();
1.1.1.2 ! misho      26:   $alldata = '';
1.1       misho      27:   ob_start(); // start output buffering
                     28:   curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
                     29:   curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
1.1.1.2 ! misho      30:     $GLOBALS['alldata'] .= $data;
1.1       misho      31:     return strlen ($data);
                     32:   });
1.1.1.2 ! misho      33:    
1.1       misho      34:   curl_exec($ch);
                     35:   curl_close($ch);
1.1.1.2 ! misho      36:   ob_end_flush();
        !            37:   echo "Data: $alldata";
1.1       misho      38: ?>
                     39: ===DONE===
                     40: --EXPECTF--
                     41: *** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***
                     42: Data: Hello World!
                     43: Hello World!===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>