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

curl_exec() is missing #1998

Closed
jcvignoli opened this issue Nov 15, 2024 · 6 comments
Closed

curl_exec() is missing #1998

jcvignoli opened this issue Nov 15, 2024 · 6 comments

Comments

@jcvignoli
Copy link

Following the implementation of Curl, I tried to use my plugin with playground.

It seems something is still missing, as I get the error

PHP Fatal error: Uncaught Error: Call to undefined function Imdb\curl_exec() in /wordpress/wp-content/plugins/lumiere-movies/vendor/jcvignoli/imdbphp/src/Imdb/Request.php:99

where line 99 reads as

$this->page = curl_exec($this->ch);

Thanks!

@bgrgicak
Copy link
Collaborator

@jcvignoli Curl requires networking to work correctly. Could you please try it again with networking set to yes in the URL?

@jcvignoli
Copy link
Author

@bgrgicak I tried with networking set to yes, and got the following:

[15-Nov-2024 12:03:07 UTC] PHP Fatal error: Uncaught Imdb\Exception\Http: Failed fetch url [https://www.imdb.com/find?s=tt&q=fight+club] Empty reply from server in /wordpress/wp-content/plugins/lumiere-movies/vendor/jcvignoli/imdbphp/src/Imdb/Request.php:105

The line 105 throws an exception if curl fails. Here is the method that fails, with numbered lines:

95      public function sendRequest()
96     {
97        $this->responseHeaders = array();
98        curl_setopt($this->ch, CURLOPT_HTTPHEADER, $this->requestHeaders);
99        $this->page = curl_exec($this->ch);
100       curl_close($this->ch);
101        if ($this->page !== false) {
102            return true;
103        }
104        if ($this->config->throwHttpExceptions) {
105            throw new Exception\Http("Failed fetch url [$this->urltoopen] " . curl_error($this->ch));
106        }
107        return false;
108    }

This method perfectly works on a server, and the link "https://www.imdb.com/find?s=tt&q=fight+club" is available.

@adamziel adamziel moved this from Needs Author's Reply to Inbox in Playground Board Nov 15, 2024
@akirk
Copy link
Member

akirk commented Nov 18, 2024

@jcvignoli because Playground is running in the browser, the URL being requested needs to be CORS enabled for playground.wordpress.net. Could you check the network tab of your browser's developer tools if you can see the request being made there?

Edit: There have been efforts to create a CORS proxy but it's not ready yet.

@adamziel
Copy link
Collaborator

Looping in @brandonpayton on advancing the CORS proxy and moving it to another domain to enable expanding the support.

@jcvignoli
Copy link
Author

Hi @akirk
Indeed, I confirm it's CORS related issue:
Access to fetch at 'https://www.imdb.com/find%3Fs=tt&q=fight+club?s=tt&q=fight+club' from origin 'https://playground.wordpress.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled

@adamziel
Copy link
Collaborator

adamziel commented Dec 11, 2024

Since the original description is about curl_exec() being missed and that was solved by enabling the networking, I'll close this issue. Enabling the networking by default is a planned feature and that will resolve the confusion point.

As for the CORS proxy – it is on its way to being enabled and there's a few related issues where this work can be tracked.

Also, once it's enabled there will be an announcement on the #playground slack channel and make.w.org/playground.

@github-project-automation github-project-automation bot moved this from Inbox to Done in Playground Board Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants