PHP Raw Curl

The regular PHP file functions sometimes are too slow and inadequate. In such cases you can use the raw curl command, which is faster and more adaptable.

PHP Raw Curl

The regular PHP file functions sometimes are too slow and inadequate. In such cases you can use the raw "curl" command, which is faster and more adaptable.

1. Get the Headers of Remote File using cURL


/**
* Gets the headers using
* @param String $url
* @return String
*/
function rawCurlGetHeaders($url) {
    $cmd = 'curl ' . $url . ' --head';
    exec($cmd, $out);
    return $out;
}

2. Download Remote File using cURL

On an average server a 120MB file will take about 20secs. Impressive.

function rawCurlDownload($sourceUrl, $targetPath, $options = []) {

    $headers = isset($options['headers']) ? '--header "' . $options['headers'] . '"' : '';

    $cmd = 'curl -X GET ' . $headers . ' --output "' . $targetPath . '" -O ' . $sourceUrl . '';

    exec($cmd, $out);

    if (file_exists($targetPath) == false) {

        return false;

    }

    return true;

}
Previous
Easiest JQuery Template
Next
Get the Domain Name in Wordpress

Keep Reading

Explore more articles and insights

A Big, Opinionated List of PHP Libraries (2026 Edition)

A Big, Opinionated List of PHP Libraries (2026 Edition)

Read Article
Ork: SSH Server Automation in Go

Ork: SSH Server Automation in Go

Read Article
Deno Deploy Killed My Start Page

Deno Deploy Killed My Start Page

Read Article
View All Blog Posts