Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please check if cURL/SSL is installed and activated #46

Open
fa-m opened this issue Sep 3, 2017 · 0 comments
Open

Please check if cURL/SSL is installed and activated #46

fa-m opened this issue Sep 3, 2017 · 0 comments

Comments

@fa-m
Copy link

fa-m commented Sep 3, 2017

/**
     * Fetches a URI and parses it for Open Graph data, returns
     * false on error.
     *
     * @param $URI    URI to page to parse for Open Graph data
     * @return OpenGraph
     */
    static public function fetch($URI) {


        try {
            $curl = curl_init($URI);
            if ($curl === false) {
                throw new Exception('failed to initialize');
            }


            curl_setopt($curl, CURLOPT_FAILONERROR, true);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, 15);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

            $response = curl_exec($curl);
            if ($response === false) {
                throw new Exception(curl_error($curl), curl_errno($curl));
            }

            curl_close($curl);

            if (!empty($response)) {
                return self::_parse($response);
            } else {
                return false;
            }
        } catch (Exception $e) {

            trigger_error(sprintf(
                'Curl failed with error #%d: %s',
                $e->getCode(), $e->getMessage()),
                E_USER_ERROR);
        }
    }

This got it working for me after checking cURL manually and then with problems with the SSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant