PHP 5는 지원이 종료되었으며 2026년 1월 31일에 지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 PHP 5 애플리케이션을 배포할 수 없습니다. 기존 PHP 5 애플리케이션은 지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다. 지원되는 최신 PHP 버전으로 마이그레이션하는 것이 좋습니다.
Cloud Storage용 App Engine 스트림 래퍼는 여러 기본 PHP 파일 시스템 함수를 제공합니다. 일부 함수는 지원되지 않으며, 일부는 수정된 형태로 지원됩니다. 다음 표에 이러한 각 기본 함수와 함께 함수 지원 여부가 나열되어 있습니다. 함수가 지원되지만 수정 또는 제한된 형태로 지원되는 경우에는 해당 내용이 설명되어 있습니다.
애플리케이션 보안을 위해 Cloud Storage 파일에서 include 또는 require 기능이 기본적으로 중지되지만 다음과 같이 이 기능을 사용 설정할 수 있습니다.
애플리케이션에서 Google Cloud Storage의 PHP 코드를 include 또는 require하려면 php.ini 파일에서 google_app_engine.allow_include_gs_buckets 지시문을 사용하여 이 파일이 포함되는 버킷을 지정해야 합니다.
커스텀 메타데이터 읽기 및 쓰기
Google Cloud Storage에 작성된 파일에 커스텀 메타데이터를 첨부하려면 $options에 메타데이터를 추가한 후 file_put_contents 호출에 사용되는 스트림 컨텍스트를 만듭니다.
이 예시에서 foo라는 메타데이터에는 far 값이 지정되고 또 다른 bar라는 메타데이터에는 boo 값이 지정되며 콘텐츠 유형도 text/plain로 설정됩니다. 스트림 컨텍스트는 다음과 같이 $options의 정보를 통해 생성되고 파일은 file_put_contents()를 통해 메타데이터 및 콘텐츠 유형과 함께 Cloud Storage에 기록됩니다.
기본적으로 Cloud Storage용 App Engine 스트림 래퍼는 이후 읽기 작업의 성능 향상을 위해 파일 읽기를 memcache에 캐시합니다. 캐싱은 스트림 컨텍스트에서 enable_cache 지시문을 사용하여 해제할 수 있습니다.
성능을 더욱 개선하기 위해 낙관적 캐싱을 사용할 수도 있으며, 이 경우 enable_optimistic_cache 지시문(기본적으로 false로 설정됨)을 사용하여 마지막으로 캐시된 이후 Google Cloud Storage에서 기본 객체가 변경되었는지 여부를 확인하지 않고 캐시에서 파일 객체를 읽습니다.
낙관적 캐싱은 한 번 쓰고 여러 번 읽는 상황에 이상적입니다.
read_cache_expiry_seconds 지시문을 사용하여 다음 읽기 시도 시 객체가 다시 캐시되기 전까지 캐시된 객체가 유효한 상태로 유지되는 시간을 변경할 수도 있습니다. 기본적으로 1시간(3600)으로 설정됩니다.
이 예시에서는 낙관적 캐싱이 사용되었으며 5분 후에 Google Cloud Storage에서 다시 캐시되도록 파일 객체가 구성되었습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eThis API supports first-generation runtimes and is used when upgrading to second-generation runtimes, with specific migration guidance available for App Engine PHP 7/8 runtimes.\u003c/p\u003e\n"],["\u003cp\u003eThe App Engine stream wrapper for Cloud Storage allows you to configure stream options like \u003ccode\u003eacl\u003c/code\u003e, \u003ccode\u003eContent-Type\u003c/code\u003e, \u003ccode\u003eContent-Disposition\u003c/code\u003e, and \u003ccode\u003eContent-Encoding\u003c/code\u003e, along with caching directives like \u003ccode\u003eenable_cache\u003c/code\u003e and \u003ccode\u003eenable_optimistic_cache\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMany PHP filesystem functions are supported with the App Engine stream wrapper for Cloud Storage, but some, including \u003ccode\u003echgrp\u003c/code\u003e, \u003ccode\u003echmod\u003c/code\u003e, and \u003ccode\u003echown\u003c/code\u003e, are not supported and will always return \u003ccode\u003efalse\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCustom metadata can be added to files being written to Google Cloud Storage by including a \u003ccode\u003emetadata\u003c/code\u003e array in the \u003ccode\u003e$options\u003c/code\u003e when creating the stream context, and this metadata can be retrieved through \u003ccode\u003eCloudStorageTools\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFile reads are cached in memcache by default to improve performance, and this behavior can be modified with caching directives, including disabling it completely or implementing optimistic caching for write-once, read-many situations.\u003c/p\u003e\n"]]],[],null,["# Advanced PHP 5 File Management\n\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| php-gen2\n|\n| /services/access). If you are updating to the App Engine PHP 7/8 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/php-differences) to learn about your migration options for legacy bundled services.\n\n\u003cbr /\u003e\n\nPermissions, caching and metadata options\n-----------------------------------------\n\nThe App Engine stream wrapper for Cloud Storage provides the following\noptions to configure your stream:\n\nThe following snippet shows how to use stream options: \n\n $options = ['gs' =\u003e ['Content-Type' =\u003e 'text/plain']];\n $context = stream_context_create($options);\n file_put_contents(\"gs://${my_bucket}/hello_options.txt\", $newFileContent, 0, $context);\n\nIn the snippet above, `$options` is a set of arguments that the stream will use\nwhen writing new objects, which can be set as the default options using\n[`stream_context_set_default`](http://php.net/manual/function.stream-context-set-default.php).\n\nPHP 5 filesystem functions support on Cloud Storage\n---------------------------------------------------\n\nThe App Engine stream wrapper for Cloud Storage supports many native PHP\nfilesystem functions. Some functions are not supported, and some have modified\nsupport. The following table lists each of these native functions, indicating\nwhether the function is supported or not. If a function is supported but with\nmodifications or limitations, those are described.\n\nNote that the file stat functions in the table above (`file_exists`, `filemtime`,\n`filesize`, `fstat`, `is_file`, `is_dir`, `is_writable`, and `stat`) are cached\non a per-request basis. You can clear this cache by calling `clearstatcache`.\n\nIn addition, the following PHP directory-reading functions are supported:\n\n| **Note:** As Cloud Storage listing operations are [eventually consistent](/storage/docs/consistency), `readdir` might not reflect the change immediately after an object is added, renamed or removed.\n\nUsing PHP 5 `include` and `require`\n-----------------------------------\n\nTo help maintain the security of your application, the ability to `include` or\n`require` from a Cloud Storage file is disabled by default, but you can enable\nit, as follows:\n\nTo [`include`](http://php.net/manual/function.include.php) or\n[`require`](http://php.net/manual/function.require.php) PHP code\nfrom Google Cloud Storage in your application, you must specify which buckets\ncontain those files using the `google_app_engine.allow_include_gs_buckets`\ndirective in your [`php.ini`](/appengine/docs/legacy/standard/php/config/php_ini) file.\n\nReading and writing custom metadata\n-----------------------------------\n\nTo attach custom metadata to a file being written to Google Cloud Storage, add\nthe metadata to `$options` before creating the stream context used for\nthe [file_put_contents](http://php.net/file-put-contents.php) call.\n\nIn this example, metadata named `foo` is given the value `far`,\nand another named `bar` is given the value `boo`. The example also sets the\ncontent type to `text/plain`. The stream context is created using this\ninformation in `$options` as shown, and the file is written to Cloud Storage by\nusing `file_put_contents()`, along with the metadata and content type: \n\n $metadata = ['foo' =\u003e 'bar', 'baz' =\u003e 'qux'];\n $options = [\n 'Content-Type' =\u003e 'text/plain',\n 'metadata' =\u003e $metadata\n ];\n $context = stream_context_create(['gs' =\u003e $options]);\n file_put_contents(\"gs://${my_bucket}/hello_metadata.txt\", $newFileContent, 0, $context);\n\nTo read the custom metadata and content type for a file, call `fopen` on the\nfile and then use [`CloudStorageTools::getContentType()`](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.cloud_storage.CloudStorageTools#method_getContentType)\nto get the content type and [`CloudStorageTools::getMetaData()`](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.cloud_storage.CloudStorageTools#method_getMetaData)\nto get the metadata.\n\nThe custom metadata and content type are available once you have the file\npointer returned from the `fopen` call. \n\n $fp = fopen(\"gs://${my_bucket}/hello_metadata.txt\", 'r');\n $content_type = CloudStorageTools::getContentType($fp);\n $metadata = CloudStorageTools::getMetaData($fp);\n\nCached file reads\n-----------------\n\nBy default, the App Engine stream wrapper for Cloud Storage caches file\nreads into [memcache](/appengine/docs/legacy/standard/php/memcache) to improve\nperformance on subsequent reads. Caching can be turned off using the `enable_cache`\ndirective in the stream context.\n| **Note:** When caching is enabled, files read from Cloud Storage are cached as they are read, and the cache also contains the file information regarding writability. So, be aware that `is_writable` could be querying stale file information. Also, if you change the ACL on a Cloud Storage bucket to either grant or deny write permissions to the application, this change might take some time to be reflected.\n\nFor further performance improvement, you can also enable optimistic caching, which\nwill read the file object from the cache without seeing whether the underlying object\nwas changed in Google Cloud Storage since the last time it was cached, using\nthe `enable_optimistic_cache` directive (set to `false` by default).\nOptimistic caching is ideal for write-once, read-many scenarios.\n\nYou can also change the length of time\nthat a cached object remains valid by using the `read_cache_expiry_seconds` directive,\nafter which time the object will be re-cached upon the next read attempt. By default\nthis is set to 1 hour (`3600`).\n\nIn this example, optimistic caching is turned on, and file objects are configured\nto be marked for re-caching from Google Cloud Storage after 5 minutes. \n\n $options = [\n 'gs' =\u003e [\n 'enable_cache' =\u003e true,\n 'enable_optimistic_cache' =\u003e true,\n 'read_cache_expiry_seconds' =\u003e 300,\n ]\n ];\n $context = stream_context_create($options);\n file_put_contents(\"gs://${my_bucket}/hello_caching.txt\", $newFileContent, 0, $context);"]]