-
Notifications
You must be signed in to change notification settings - Fork 43
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
[Question] Examples with PHP / Symfony #93
Comments
Did you set the |
Well ... no 🤦Thanks for that. Still, after adding it to the Dockerfile though (with <?php
$url = 'https://kitsu.app/api/graphql';
$query = '{"query": "query { findAnimeById(id: 1) { id } }"}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
$response = curl_exec($ch);
if ($response === false) {
echo 'cURL Error: ' . curl_error($ch);
} else {
echo "Response: " . $response;
}
curl_close($ch); Result (not sure about the version warning here though)
But not for existing Symfony HTTP clients calls $result = $this->httpClient->request(
'POST',
'https://kitsu.app/api/graphql',
[
'json' => ['query' => 'query { findAnimeById(id: 1) { id } }"}'],
]
);
dump($result->getContent()); Result It seems to follow the pattern of failing from I was not sure, but it seems related to getting the (compressed) data (by looking on what After trying several things, I've found that when adding the header Now adding that header is just a workaround and I can't even convince myself it's a good one at that. @lexiforest If you have ideas on why this occurs, or have additional ideas/suggestion please let me know 👍 |
By default, curl-impersonate add the browser default headers, which include |
@lexiforest Thanks for the response. Let me first start of by saying that I've finally have the given example working with the default HTTP client, without additional This now works: $result = $this->httpClient->request(
'POST',
'https://kitsu.app/api/graphql',
[
'json' => ['query' => 'query { findAnimeById(id: 1) { id } }"}'],
]
);
dump($result->getContent()); With the following in the Dockerfile: ENV CURL_IMPERSONATE=chrome131
COPY --from=ghcr.io/tarampampam/curl:8.11.1 /bin/curl /bin/curl
RUN <<EOT bash
set -ex
curl -L --retry 3 --retry-connrefused --retry-delay 2 --fail-with-body -o /tmp/curl-impersonate.tar.gz https://github.com/lexiforest/curl-impersonate/releases/download/v0.8.2/curl-impersonate-v0.8.2.x86_64-linux-gnu.tar.gz
tar -xzf /tmp/curl-impersonate.tar.gz -C /usr/local/bin --no-same-owner
curl -L --retry 3 --retry-connrefused --retry-delay 2 --fail-with-body -o /tmp/libcurl-impersonate.tar.gz https://github.com/lexiforest/curl-impersonate/releases/download/v0.8.2/libcurl-impersonate-v0.8.2.x86_64-linux-gnu.tar.gz
tar -xzf /tmp/libcurl-impersonate.tar.gz -C /tmp --no-same-owner
mv /tmp/libcurl-impersonate-* /usr/lib/x86_64-linux-gnu/
rm -f /tmp/*
ldconfig
EOT
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libcurl-impersonate-chrome.so.4.8.0 After the above was working, I've found myself clicking through my application, and finding that calls that were made internally through other services, like Meilisearch, were now also failing with
After further debugging the Sidenote: I've created a temporary patch for myself for this for the --- CurlHttpClient.php 2025-01-09 21:57:43.446365726 +0000
+++ CurlHttpClient.php 2025-01-09 21:57:20.102366512 +0000
@@ -211,6 +211,7 @@
if (\extension_loaded('zlib') && !isset($options['normalized_headers']['accept-encoding'])) {
$options['headers'][] = 'Accept-Encoding: gzip'; // Expose only one encoding, some servers mess up when more are provided
+ $options['normalized_headers']['accept-encoding'] = 'gzip';
}
$body = $options['body']; |
I've been trying to setup
curl-impersonate
with Symfony's CurlHttpClient while using Docker, but I'm failing to get it to work. The binaries work fine on there own so it seems related to the extension/how to use it.I've tried according to the original docs to install, but without any help. Also tried a comment I saw in the original repo, but also didn't work.
The question is if there are any users of
curl-impersonate
that got this working in PHP/Symfony to have the curl client usecurl-impersonate
internally. Any bit of imformation would be appreciated.Dockerfile
(part for installing curl-impersonate)RUN <<EOT bash set -ex curl -L --retry 3 --retry-connrefused --retry-delay 2 --fail-with-body -o /tmp/curl-impersonate.tar.gz https://github.com/lexiforest/curl-impersonate/releases/download/v0.8.2/curl-impersonate-v0.8.2.x86_64-linux-gnu.tar.gz tar -xzf /tmp/curl-impersonate.tar.gz -C /usr/local/bin --no-same-owner curl -L --retry 3 --retry-connrefused --retry-delay 2 --fail-with-body -o /tmp/libcurl-impersonate.tar.gz https://github.com/lexiforest/curl-impersonate/releases/download/v0.8.2/libcurl-impersonate-v0.8.2.x86_64-linux-gnu.tar.gz tar -xzf /tmp/libcurl-impersonate.tar.gz -C /tmp --no-same-owner mv /tmp/libcurl-impersonate-* /usr/lib/x86_64-linux-gnu/ cp /usr/lib/x86_64-linux-gnu/libcurl-impersonate-chrome.so.4.8.0 /usr/lib/x86_64-linux-gnu/libcurl.so.4.8.0 rm -f /tmp/* ldconfig EOT
Test binary
Respone
Test application
Symfony POST request.
Response
Returns
403
due to CloudFlare (likely fingerprint?)Standalone cURL
php snippet.php
Response
Returns
403
again.php -r 'print_r(curl_version());'
(in container)The text was updated successfully, but these errors were encountered: