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

[BUGFIX] Fix compatibility with php8 curl init #8

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions Classes/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Macopedia\CachePurger;

use CurlHandle;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -14,14 +15,12 @@
use function curl_getinfo;
use function curl_init;
use function curl_multi_add_handle;
use function curl_multi_close;
use function curl_multi_exec;
use function curl_multi_init;
use function curl_multi_remove_handle;
use function curl_multi_select;
use function curl_setopt;
use function is_array;
use function is_resource;
use const CURLM_CALL_MULTI_PERFORM;
use const CURLM_OK;
use const CURLOPT_CUSTOMREQUEST;
Expand Down Expand Up @@ -71,14 +70,10 @@ public function execute(): void

$multiHandle = curl_multi_init();

if (!is_resource($multiHandle)) {
return;
}

foreach ($this->settings['varnish.'] as $varnishInstance) {
foreach ($this->clearQueue as $tag) {
$ch = $this->getCurlHandleForCacheClearingAsTag($tag, $varnishInstance);
if (!is_resource($ch)) {
if (!$ch) {
continue;
}
$curlHandles[] = $ch;
Expand All @@ -87,7 +82,6 @@ public function execute(): void
}

if (count($curlHandles) === 0) {
curl_multi_close($multiHandle);
return;
}

Expand All @@ -113,10 +107,6 @@ public function execute(): void
}

foreach ($curlHandles as $ch) {
if (!is_resource($ch)) {
continue;
}

if (curl_errno($ch) !== 0) {
$this->logger->error('error: ' . curl_error($ch));
} else {
Expand All @@ -127,8 +117,6 @@ public function execute(): void
curl_close($ch);
}

curl_multi_close($multiHandle);

$this->clearQueue = [];
}

Expand Down Expand Up @@ -162,7 +150,7 @@ public function clearCache(?string $cmd): void
/**
* @param string $tag
* @param string $varnishUrl
* @return false|resource
* @return false|CurlHandle
*/
protected function getCurlHandleForCacheClearingAsTag(string $tag, string $varnishUrl)
{
Expand All @@ -172,7 +160,7 @@ protected function getCurlHandleForCacheClearingAsTag(string $tag, string $varni
/**
* @param string $varnishUrl
* @param string $header
* @return false|resource
* @return false|CurlHandle
*/
protected function createCurlHandle(string $varnishUrl, string $header, string $method = 'BAN')
{
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# CachePurger for Varnish
# CachePurger for Varnish

- supports clear per page or all pages
- supports TYPO3 9.5-10.4
- requires php >= 7.4
- supports TYPO3 >= 11.5
- requires php >= 8.1

# Example configuration in Typoscript
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": ["GPL-2.0+"],
"keywords": ["TYPO3 CMS", "Purge"],
"require": {
"typo3/cms-core": "^9.5 || ^10.4 || ^11.5"
"typo3/cms-core": "^11.5"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
'title' => 'Cache Purger',
'description' => 'Purge cached URLs within Varnish instances',
'category' => 'misc',
'version' => '1.0.5',
'version' => '2.0.0',
'state' => 'stable',
'clearCacheOnLoad' => 0,
'constraints' => [
'depends' => [
'typo3' => '9.5.0-11.5.99',
'typo3' => '11.5.0-11.5.99',
],
'conflicts' => [],
'suggests' => [],
Expand Down