Engineering Blog

An Intro to Curl & Fsockopen

What are they?

cURL and Fsock are both methods used to communicate with different types of servers using communication protocols. Fsock is included in PHP and cURL is a library that can be installed on a server or utilized on many different platforms.





$fp = fsockopen("", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)
\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= 'Host:\r\n'; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?>-->

How to check if you have cURL enabled

Run phpinfo() to see if cURL is enabled on your server then navigate to the cURL section. You will see the setting cURL support – enabled or disabled.

Or use the php script below to create a curl_check.php file

// Script to test if the cURL extension is installed on this server
// Define function to test
function _is_curl_installed() {
    if (in_array('curl', get_loaded_extensions())) {
        return true;
    else {
        return false;
// Output text to user based on test
if (_is_curl_installed()) {
    echo 'cURL is installed on this server';
} else {
    echo 'cURL is NOT installed on this server';

After saving this file as curl_check.php load it on a server installed with PHP and run the path yourpath/curl_check.php you will see a message shown that notifies you if cURL is enabled or disabled

Check if fsockopen function exists


Normally, by default your server will have cURL enabled and ready to use on your server. It is the most commonly used method to communicate to different types of servers. If you’re ever having a problem communicating with a server run one of the above checks to verify your cURL and Fsock is working correctly.


About Zoie Carnegie

Graduated from NAIT Digital Media and IT specializing in application development. PHP is my favorite language. I am a continuous learner always trying new languages, applications, frameworks. Passions are Programming, Photography and Travel.

Related Posts