'500 Internal Server Error with PHP Laravel fsockopen()

I'm trying to whois query to whois name servers for domain availability. In localhost these codes are working great but in real server i'm getting 500 internal server error (Laravel blade files).

    
    @php

    $fp = fsockopen("whois.verisign-grs.com", 43);
    $domain= "example.com";

    fputs($fp, $domain);
    $whois = "";
    while (!feof($fp)) {
      $whois .= fgets($fp, 128);
    }

    fclose($fp);

    @endphp


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source