Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
Proxy
Commits
ed87bfe1
Commit
ed87bfe1
authored
Jan 18, 2022
by
Dominik Hebeler
Browse files
Cache non 200 Status codes only for 30 seconds
parent
de9c29ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/Console/Commands/RequestFetcher.php
View file @
ed87bfe1
...
...
@@ -88,7 +88,7 @@ class RequestFetcher extends Command
$answersRead
=
$status
[
0
];
$messagesLeft
=
$status
[
1
];
$newJobs
=
$this
->
checkNewJobs
(
$operationsRunning
,
$messagesLeft
);
if
(
$newJobs
===
0
&&
$answersRead
===
0
)
{
usleep
(
10
*
1000
);
}
...
...
@@ -148,18 +148,23 @@ class RequestFetcher extends Command
$infos
=
explode
(
";"
,
$infos
);
$resulthash
=
$infos
[
0
];
$cacheDurationMinutes
=
intval
(
$infos
[
1
]);
if
(
curl_errno
(
$info
[
"handle"
])){
Log
::
error
(
curl_error
(
$info
[
"handle"
]));
}
$result
=
$this
->
parseResponse
(
$info
[
"handle"
]);
Redis
::
pipeline
(
function
(
$pipe
)
use
(
$resulthash
,
$result
,
$cacheDurationMinutes
)
{
$pipe
->
lpush
(
$resulthash
,
json_encode
(
$result
));
$pipe
->
expire
(
$resulthash
,
15
);
});
// Cache non 200 Status codes only for 30 seconds
if
(
intval
(
$result
[
'http-code'
])
!==
200
){
$cacheDurationMinutes
=
0.5
;
}
if
(
$cacheDurationMinutes
>
0
)
{
try
{
Cache
::
put
(
$resulthash
,
$result
,
$cacheDurationMinutes
*
60
);
...
...
@@ -186,7 +191,7 @@ class RequestFetcher extends Command
];
}
$httpResponse
=
\
curl_multi_getcontent
(
$ch
);
if
(
empty
(
$httpResponse
))
{
return
null
;
}
...
...
@@ -204,7 +209,7 @@ class RequestFetcher extends Command
$headers_arr
[
strtolower
(
"
{
$matches
[
0
]
}
"
)]
=
trim
(
$matches
[
1
]);
}
}
// Unzip if content-encoding is gzip
if
(
!
empty
(
$headers_arr
[
"content-encoding"
])
&&
strtolower
(
$headers_arr
[
"content-encoding"
])
===
"gzip"
){
$body
=
gzdecode
(
$body
);
...
...
@@ -220,7 +225,7 @@ class RequestFetcher extends Command
$sanitizedHeaders
[
$key
]
=
$value
;
}
}
$response
=
[
"http-code"
=>
$httpcode
,
"body"
=>
base64_encode
(
$body
),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment