PHP 5 has reached end of support and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy PHP 5
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing PHP
5 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of PHP.
\google\appengine\ext\cloud_storage_streams\CloudStorageClient
Stay organized with collections
Save and categorize content based on your preferences.
ABSTRACT
CloudStorageClient is the base class for classes that are used to communicate
with Google Cloud Storage via the PHP streams interface.
CloudStorageClient provides default fail implementations for all of the
methods that the stream wrapper might potentially call. Derived classes then
only implement the methods that are relevant to the operations that they
perform.
Constants
DEFAULT_READ_SIZE
DEFAULT_READ_CACHE_EXPIRY_SECONDS
DEFAULT_MAXIMUM_NUMBER_OF_RETRIES
DEFAULT_CONNECTION_TIMEOUT_SECONDS
DEFAULT_WRITABLE_CACHE_EXPIRY_SECONDS
READ_SCOPE
WRITE_SCOPE
FULL_SCOPE
PARTIAL_CONTENT_RANGE_FORMAT
FINAL_CONTENT_RANGE_FORMAT
FINAL_CONTENT_RANGE_NO_DATA
DELIMITER
FOLDER_SUFFIX
WRITABLE_TEMP_FILENAME
S_IFREG
S_IFDIR
S_IRWXU
S_IRUSR
S_IWUSR
S_IXUSR
S_IRWXG
S_IRGRP
S_IWGRP
S_IXGRP
S_IRWXO
S_IROTH
S_IWOTH
S_IXOTH
CONTENT_RANGE_REGEX
Memcache key format for caching the results of reads from GCS. The
parameters are the object url (as a string) and the read range, as a
string (e.g. bytes=0-512000).
Example key for a cloud storage file gs://bucket/object.png
_ah_gs_read_cache_https://storage.googleapis.com/bucket/object.png_bytes=0-524287
Memcache key format for caching the results of reads from GCS. If the key
generated using the filename and range is longer than the maximum allowed
memcache key we hash down the value and use this format instead.
MEMCACHE_KEY_MAX_LENGTH
The maximum length of a memcache key.
Memcache key format for caching the results of checking if a bucket is
writable. The only way to check if an app can write to a bucket is by
actually writing a file. As the ACL on a bucket is unlikely to change
then we can cache the result.
Methods
__construct
__construct(string $bucket, string $object = null, resource $context = null)
Construct an object of CloudStorageClient.
Parameters
Name |
Description |
$bucket
|
string
The name of the bucket. |
$object
|
string
The name of the object, or null if there is no
object. |
$context
|
resource
The stream context to use. |
__destruct
__destruct()
initialize
initialize()
dir_readdir
dir_readdir()
dir_rewinddir
dir_rewinddir()
close
close()
delete
delete()
eof
eof()
flush
flush()
read
read( $count_bytes)
Parameters
Name |
Description |
$count_bytes
|
|
seek
seek( $offset, $whence)
Parameters
Name |
Description |
$offset
|
|
$whence
|
|
stat
stat()
tell
tell()
write
write( $data)
Parameters
getMetaData()
Subclass can override this method to return the metadata of the underlying
GCS object.
getContentType
getContentType()
Subclass can override this method to return the MIME content type of the
underlying GCS object.
createObjectUrl
STATIC
createObjectUrl( $bucket, $object = null)
Create a URL for a target bucket and optional object.
Parameters
Name |
Description |
$bucket
|
|
$object
|
|
clearStatCache
STATIC
clearStatCache(string $filename = null)
Clear the stat cache.
Parameters
Name |
Description |
$filename
|
string
Option filename to clear from the cache. |
getReadMemcacheKey
STATIC
getReadMemcacheKey(string $url, string $range) : string
Create a memcache key for the read data cache. If the filename is long
enough that the key would exceed memcache limits, then a hash of the
filename and the range is used to generate the key.
We prefer the human readable key format where possible so users can easily
identify which files and segments are stored in memcache.
Parameters
Name |
Description |
$url
|
string
The url of the file that contains the data being cached. |
$range
|
string
The range oheader f the data being cached. |
Returns
string
The memcache key to use for storing data.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003e\u003ccode\u003eCloudStorageClient\u003c/code\u003e serves as the foundational class for interacting with Google Cloud Storage through PHP streams, simplifying integration.\u003c/p\u003e\n"],["\u003cp\u003eThe class implements default behaviors, allowing derived classes to focus solely on relevant methods for their operations.\u003c/p\u003e\n"],["\u003cp\u003eSeveral constants are defined for metadata handling, default settings, access scopes, and formatting of data, such as \u003ccode\u003eMETADATA_HEADER_PREFIX\u003c/code\u003e, \u003ccode\u003eDEFAULT_READ_SIZE\u003c/code\u003e, \u003ccode\u003eREAD_SCOPE\u003c/code\u003e, \u003ccode\u003eOAUTH_TOKEN_FORMAT\u003c/code\u003e, etc.\u003c/p\u003e\n"],["\u003cp\u003eThe class provides various methods for managing files and directories, like \u003ccode\u003eread\u003c/code\u003e, \u003ccode\u003ewrite\u003c/code\u003e, \u003ccode\u003edelete\u003c/code\u003e, \u003ccode\u003estat\u003c/code\u003e, and also includes methods for caching data, such as \u003ccode\u003egetReadMemcacheKey\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eCloudStorageClient\u003c/code\u003e offers static methods, such as \u003ccode\u003ecreateObjectUrl\u003c/code\u003e for generating URLs, and \u003ccode\u003eclearStatCache\u003c/code\u003e for managing the file information cache.\u003c/p\u003e\n"]]],[],null,["# \\google\\appengine\\ext\\cloud_storage_streams\\CloudStorageClient\n\nABSTRACT\n\nCloudStorageClient is the base class for classes that are used to communicate\nwith Google Cloud Storage via the PHP streams interface.\n\nCloudStorageClient provides default fail implementations for all of the\nmethods that the stream wrapper might potentially call. Derived classes then\nonly implement the methods that are relevant to the operations that they\nperform.\n\nConstants\n---------\n\n### METADATA_HEADER_PREFIX\n\nPrefix for all metadata headers used when parsing and rendering.\n\n### DEFAULT_READ_SIZE\n\n### DEFAULT_READ_CACHE_EXPIRY_SECONDS\n\n### DEFAULT_MAXIMUM_NUMBER_OF_RETRIES\n\n### DEFAULT_CONNECTION_TIMEOUT_SECONDS\n\n### DEFAULT_WRITABLE_CACHE_EXPIRY_SECONDS\n\n### READ_SCOPE\n\n### WRITE_SCOPE\n\n### FULL_SCOPE\n\n### OAUTH_TOKEN_FORMAT\n\n### PARTIAL_CONTENT_RANGE_FORMAT\n\n### FINAL_CONTENT_RANGE_FORMAT\n\n### FINAL_CONTENT_RANGE_NO_DATA\n\n### DELIMITER\n\n### FOLDER_SUFFIX\n\n### WRITABLE_TEMP_FILENAME\n\n### S_IFREG\n\n### S_IFDIR\n\n### S_IRWXU\n\n### S_IRUSR\n\n### S_IWUSR\n\n### S_IXUSR\n\n### S_IRWXG\n\n### S_IRGRP\n\n### S_IWGRP\n\n### S_IXGRP\n\n### S_IRWXO\n\n### S_IROTH\n\n### S_IWOTH\n\n### S_IXOTH\n\n### CONTENT_RANGE_REGEX\n\n### MEMCACHE_KEY_FORMAT\n\nMemcache key format for caching the results of reads from GCS. The\nparameters are the object url (as a string) and the read range, as a\nstring (e.g. bytes=0-512000).\n\nExample key for a cloud storage file gs://bucket/object.png\n_ah_gs_read_cache_https://storage.googleapis.com/bucket/object.png_bytes=0-524287\n\n### MEMCACHE_KEY_HASH_FORMAT\n\nMemcache key format for caching the results of reads from GCS. If the key\ngenerated using the filename and range is longer than the maximum allowed\nmemcache key we hash down the value and use this format instead.\n\n### MEMCACHE_KEY_MAX_LENGTH\n\nThe maximum length of a memcache key.\n\n### WRITABLE_MEMCACHE_KEY_FORMAT\n\nMemcache key format for caching the results of checking if a bucket is\nwritable. The only way to check if an app can write to a bucket is by\nactually writing a file. As the ACL on a bucket is unlikely to change\nthen we can cache the result.\n\nMethods\n-------\n\n### __construct\n\n`__construct(string `$bucket`, string `$object = null`, resource `$context = null`) `\n\nConstruct an object of CloudStorageClient.\n\n#### Parameters\n\n### __destruct\n\n`__destruct() `\n\n\n### initialize\n\n`initialize() `\n\n\n### dir_readdir\n\n`dir_readdir() `\n\n\n### dir_rewinddir\n\n`dir_rewinddir() `\n\n\n### close\n\n`close() `\n\n\n### delete\n\n`delete() `\n\n\n### eof\n\n`eof() `\n\n\n### flush\n\n`flush() `\n\n\n### read\n\n`read( `$count_bytes`) `\n\n\n#### Parameters\n\n### seek\n\n`seek( `$offset`, `$whence`) `\n\n\n#### Parameters\n\n### stat\n\n`stat() `\n\n\n### tell\n\n`tell() `\n\n\n### write\n\n`write( `$data`) `\n\n\n#### Parameters\n\n### getMetaData\n\n`getMetaData() `\n\nSubclass can override this method to return the metadata of the underlying\nGCS object.\n\n### getContentType\n\n`getContentType() `\n\nSubclass can override this method to return the MIME content type of the\nunderlying GCS object.\n\n### createObjectUrl\n\n\nSTATIC\n\n`createObjectUrl( `$bucket`, `$object = null`) `\n\nCreate a URL for a target bucket and optional object.\n\n#### Parameters\n\n### clearStatCache\n\n\nSTATIC\n\n`clearStatCache(string `$filename = null`) `\n\nClear the stat cache.\n\n#### Parameters\n\n### getReadMemcacheKey\n\n\nSTATIC\n\n`getReadMemcacheKey(string `$url`, string `$range`) : string`\n\nCreate a memcache key for the read data cache. If the filename is long\nenough that the key would exceed memcache limits, then a hash of the\nfilename and the range is used to generate the key.\n\nWe prefer the human readable key format where possible so users can easily\nidentify which files and segments are stored in memcache.\n\n#### Parameters\n\n#### Returns\n\n`string`\n\nThe memcache key to use for storing data."]]