function FileCookieJar::save
Saves the cookies to a file.
Parameters
string $filename File to save:
Throws
\RuntimeException if the file cannot be found or created
1 call to FileCookieJar::save()
- FileCookieJar::__destruct in vendor/
guzzlehttp/ guzzle/ src/ Cookie/ FileCookieJar.php - Saves the file when shutting down
File
-
vendor/
guzzlehttp/ guzzle/ src/ Cookie/ FileCookieJar.php, line 57
Class
- FileCookieJar
- Persists non-session cookies using a JSON formatted file
Namespace
GuzzleHttp\CookieCode
public function save(string $filename) : void {
$json = [];
/** @var SetCookie $cookie */
foreach ($this as $cookie) {
if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) {
$json[] = $cookie->toArray();
}
}
$jsonStr = Utils::jsonEncode($json);
if (false === \file_put_contents($filename, $jsonStr, \LOCK_EX)) {
throw new \RuntimeException("Unable to save file {$filename}");
}
}