Speed up development with full-stack environments for every branch.

Learn More

Curl module example - Displaying information about the last transfer using curl_getinfo

Forked from Hello World.

361 Runs 1731 Views 649 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php

/**
 * Curl example - Displaying information about the last transfer using curl_getinfo
 */
// Create a curl handle
$ch = curl_init('http://www.google.com');

//return the transfer (the result of curl_exec()) as a string instead of outputing directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// execute the curl session
curl_exec($ch);

// Check if any error occurred
if (!curl_errno($ch)) {
    $info = curl_getinfo($ch);
    echo '<center>';
    echo '<b>Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'] . "</b><br /><br />";
    echo '<b>curl_getinfo() return:</b><br /><br />';
    foreach ($info as $i => $v) {
        echo '<b><i>'.$i . '</i></b> = ' . $v . '<br />';
    }
}
echo '</center>';
// Close handle
curl_close($ch);
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).