PHP 5는 지원이 종료되었으며 2026년 1월 31일에
지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 PHP 5 애플리케이션을 배포할 수 없습니다. 기존 PHP 5 애플리케이션은
지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다.
지원되는 최신 PHP 버전으로 마이그레이션하는 것이 좋습니다.
태스크 만들기
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 페이지에서는 작업을 만들어 push 큐에 추가하는 방법에 대해 설명합니다. 태스크를 처리하려면 새 태스크 객체를 만들어 큐에 추가해야 합니다. 태스크를 처리하는 서비스와 핸들러를 명시적으로 지정하고 필요에 따라 태스크별 데이터를 핸들러에 함께 전달할 수 있습니다. 태스크를 실행할 시간을 예약하거나 태스크가 실패할 경우 재시도할 횟수를 제한하는 등 태스크의 구성을 세부적으로 조정할 수도 있습니다.
새 태스크 만들기
태스크를 만들어 큐에 추가하려면 PushTask 객체를 만들고 이 객체의 add()
메서드를 호출합니다. add()
에 큐 이름 인수를 제공하여 queue.yaml
에 지정되는 큐에 추가할 수 있습니다. 또는 인수 없이 add()
를 호출하면 기본 큐에 태스크가 추가됩니다.
PushQueue를 사용하여 태스크를 대량으로 큐에 추가할 수도 있습니다. 다음 예시에서는 두 개의 PushTask 객체가 addTasks()
메서드를 사용하여 PushQueue에 추가됩니다.
다음 코드 샘플에서는 하나의 태스크를 추가하는 방법을 보여줍니다.
다음 코드 샘플에서는 여러 개의 태스크를 동시에 추가하는 방법을 보여줍니다.
PushTask
와 PushQueue
를 사용하는 경우 PHP 파일 상단에 다음 문을 포함하세요.
작업자 서비스 지정
큐에서 태스크를 꺼내면 태스크 큐 서비스가 작업자 서비스로 해당 태스크를 전송합니다. 모든 태스크에는 최종적으로 태스크를 수행할 서비스와 핸들러를 결정하는 target과 url이 있습니다.
target
target은 태스크를 수행하기 위해 HTTP 요청을 수신할 서비스를 지정합니다. 서비스/버전/인스턴스를 표준 형식 중 하나로 지정하는 문자열로서 가장 일반적으로 사용되는 형식은 다음과 같습니다.
service
version.service
instance.version.service
target 문자열은 앱의 도메인 이름 앞에 추가됩니다. 다음 세 가지 방법으로 태스크의 target을 설정할 수 있습니다.
태스크를 생성할 때 target을 선언합니다.
PushTask 객체 구성 시 $options
배열에 header 매개변수를 사용하여 태스크를 만들 때 대상을 명시적으로 설정할 수 있습니다.
$task = new PushTask(
'/worker',
[],
['header' => "Host: versionHostname"]);
queue-blue
의 정의에서처럼 queue.yaml
에서 큐를 정의할 때 target
지시문을 포함합니다.
target
이 있는 큐에 추가되는 모든 태스크는 태스크 생성 시점에 다른 target이 할당되었더라도 큐의 target을 사용합니다.
앞의 두 가지 방법 중 하나로 target을 지정하지 않으면 태스크를 큐에 추가한 서비스 버전이 태스크의 target이 됩니다.
기본 서비스와 버전에서 이 방식으로 태스크를 큐에 추가한 경우, 태스크가 실행되기 전에 기본 버전이 변경되면 새 기본 버전에서 태스크가 실행됩니다.
url
url
은 target 서비스의 핸들러 중에서 태스크를 수행할 핸들러 하나를 선택합니다.
url
은 target 서비스의 핸들러 URL 패턴 중 하나와 일치해야 합니다. 태스크에 지정된 메서드가 GET
또는 PULL
인 경우 url
에 쿼리 매개변수가 포함될 수 있습니다. url
을 지정하지 않으면 기본 URL인 /_ah/queue/[QUEUE_NAME]
이 사용되며, 여기서 [QUEUE_NAME]
은 태스크의 큐 이름입니다.
핸들러에 데이터 전달
태스크에 지정된 메서드가 GET
또는 PULL
인 경우에만 태스크의 URL에 포함되는 쿼리 매개변수로 데이터를 핸들러에 전달할 수 있습니다.
PushTask
생성자에는 query_data에 대한 위치 인수가 있습니다.
데이터는 보통 키-값 쌍의 사전입니다. 태스크의 메서드가 POST
또는 PUT
인 경우에는 데이터가 HTTP 요청의 페이로드에 추가됩니다. 메서드가 GET인 경우에는 URL에 쿼리 매개변수로 추가됩니다.
태스크 이름 지정
새 태스크를 만들면 기본적으로 App Engine이 태스크에 고유한 이름을 할당합니다. 그러나 name
파라미터를 사용하면 태스크 이름을 직접 할당할 수 있습니다. 태스크 이름을 직접 할당하면 명명된 태스크가 중복되지 않는다는 이점이 있습니다. 즉, 태스크 이름을 사용하면 한 태스크가 한 번만 추가됨을 보장할 수 있습니다. 중복 제거는 태스크 완료 또는 삭제 후 9일 동안 유지됩니다.
중복 제거 로직은 상당한 성능 오버헤드를 유발하며, 이에 따라 지연 시간이 증가하고 명명된 태스크와 관련하여 오류율이 상승할 수 있습니다. 태스크 이름이 타임스탬프처럼 순차적인 경우에는 이러한 비용이 대폭 증가할 수 있습니다. 따라서 이름을 직접 할당할 때는 태스크 이름에 콘텐츠의 해시와 같이 고르게 분산되는 프리픽스를 사용하는 것이 좋습니다.
태스크 이름을 직접 할당하는 경우 이름의 최대 길이는 500자이며 대문자, 소문자, 숫자, 밑줄, 하이픈을 포함할 수 있습니다.
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-04(UTC)
[[["이해하기 쉬움","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 document details how to create and enqueue tasks within push queues, using \u003ccode\u003ePushTask\u003c/code\u003e and \u003ccode\u003ePushQueue\u003c/code\u003e objects.\u003c/p\u003e\n"],["\u003cp\u003eTasks can be assigned to specific worker services and handlers via a \u003ccode\u003etarget\u003c/code\u003e (service) and \u003ccode\u003eurl\u003c/code\u003e (handler), with options to set the target when constructing the task or within the queue's configuration.\u003c/p\u003e\n"],["\u003cp\u003eData can be passed to handlers as query parameters for \u003ccode\u003eGET\u003c/code\u003e or \u003ccode\u003ePULL\u003c/code\u003e methods, or within the HTTP request payload for \u003ccode\u003ePOST\u003c/code\u003e or \u003ccode\u003ePUT\u003c/code\u003e methods, using the \u003ccode\u003ePushTask\u003c/code\u003e constructor.\u003c/p\u003e\n"],["\u003cp\u003eWhile App Engine generates unique task names, you can assign custom names for de-duplication, ensuring a task is only added once within a 9-day window, although this carries a performance overhead.\u003c/p\u003e\n"],["\u003cp\u003eThis API supports first-generation runtimes and can be used for updating to second-generation runtimes, with a migration guide available for the PHP 7/8 runtime.\u003c/p\u003e\n"]]],[],null,["# Creating Tasks\n\nThis page describes how to create tasks and place them in push queues. When you\nwant to process a task, you must create a new task object and place it on a\nqueue. You can explicitly specify the service and handler that process the task,\nand optionally pass task-specific data along to the handler. You can also\nfine-tune the configuration for the task, like scheduling a time in the future\nwhen it should be executed or limiting the number of times you want the task to\nbe retried if it fails.\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\nCreating a new task\n-------------------\n\nTo create and enqueue a task, create a [PushTask](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.taskqueue.PushTask)\nobject and call its `add()` method. You can add to a queue specified in\n`queue.yaml` by supplying a queue name argument to `add()`. Alternatively,\ncalling `add()` with no arguments will add the task to the default queue.\n\nYou can also add tasks in bulk to a queue using [PushQueue](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.taskqueue.PushQueue). In the\nfollowing example, two [PushTask](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.taskqueue.PushTask) objects are added to a\n[PushQueue](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.taskqueue.PushQueue) using the `addTasks()` method.\n\nThe following code sample shows how to add a single task: \n\n $task = new PushTask(\n '/worker',\n ['name' =\u003e 'john doe', 'action' =\u003e 'send_reminder']);\n $task_name = $task-\u003eadd();\n\nThe following code sample shows how to add multiple tasks at once: \n\n $task1 = new PushTask('/someUrl');\n $task2 = new PushTask('/someOtherUrl');\n $queue = new PushQueue();\n $queue-\u003eaddTasks([$task1, $task2]);\n\nWhen you use `PushTask` and `PushQueue`, include these statements at the top of\nyour PHP file: \n\n use google\\appengine\\api\\taskqueue\\PushTask;\n use google\\appengine\\api\\taskqueue\\PushQueue;\n\nSpecifying the worker service\n-----------------------------\n\nWhen a task is popped off its queue, the Task Queue service sends it on\nto a worker service. Every task has a *target* and a *url*, which determine\nwhat service and handler will ultimately perform the task.\n\n### `target`\n\nThe target specifies the service that will receive the HTTP request to\nperform the task. It is a string that specifies a service/version/instance in\nany one of the [canonical forms](/appengine/docs/legacy/standard/php/how-requests-are-routed#routing_via_url). The most often-used forms are: \n\n service\n version.service\n instance.version.service\n\nThe target string is prepended to the domain name of your app. There are three\nways to set the target for a task:\n\n- Declare the target when you construct the task.\n\n\n You can set the target explicitly when creating the task by using the header\n parameter in the `$options`\n array when you construct the [PushTask](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.taskqueue.PushTask#__construct)\n object:\n\n $task = new PushTask(\n '/worker',\n [],\n ['header' =\u003e \"Host: versionHostname\"]);\n\n \u003cbr /\u003e\n\n- Include a `target` directive when you define a queue in the\n `queue.yaml`, as in the [definition](/appengine/docs/legacy/standard/php/taskqueue/push/creating-push-queues) of `queue-blue`.\n All tasks added to a queue with a `target` will use that target, even if\n a different target was assigned to the task at construction time.\n\n- If no target is specified according to either of the previous two methods,\n then the task's target is the version of the service that enqueues it.\n Note that if you enqueue a task from the default service and version in\n this manner, and the default version changes before the task executes, it\n will run in the new default version.\n\n### `url`\n\nThe `url` selects one of the handlers in the target service, which will\nperform the task.\n\nThe `url` should match one of the handler URL patterns in the target\nservice. The `url` can include query parameters if the method specified in the task is\n`GET` or `PULL`. If no `url` is specified the default URL\n`/_ah/queue/[QUEUE_NAME]` is used, where `[QUEUE_NAME]` is the name of\nthe task's queue.\n\nPassing data to the handler\n---------------------------\n\nYou can pass data to the handler as query parameters in the task's URL, but\nonly if the method specified in the task is `GET` or `PULL`.\n\nThe [`PushTask`](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.taskqueue.PushTask) constructor has a positional argument for query_data.\nThe data is usually a dictionary of key-value pairs. If the task's method is\n`POST` or `PUT`, the data is added to the payload of the HTTP request. If the\nmethod is GET it is added to the URL as query parameters.\n\nNaming a task\n-------------\n\nWhen you create a new task, App Engine assigns the task a unique name by\ndefault. However, you can assign your own name to a task by using the `name`\nparameter. An advantage of assigning your own task names is that named tasks are\nde-duplicated, which means you can use task names to\nguarantee\nthat a task is only added once. De-duplication continues for 9 days after the\ntask is completed or deleted.\n\nNote that de-duplication logic introduces significant performance overhead,\nresulting in increased latencies and potentially increased error rates\nassociated with named tasks. These costs can be magnified significantly if task\nnames are sequential, such as with timestamps. So, if you assign your own names,\nwe recommend using a well-distributed prefix for task names, such as a hash of\nthe contents.\n\nIf you assign your own names to tasks, note that the maximum name length is 500\ncharacters, and the name can contain uppercase and lowercase letters, numbers\nunderscores, and hyphens.\n\nWhat's next\n-----------\n\n- Learn how to [create task\n handlers](/appengine/docs/legacy/standard/php/taskqueue/push/creating-handlers)."]]