• EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

이 한글 문서는 사용자의 편의를 위해 기계 번역되었습니다.

영문본과 번역본이 일치하지 않는 경우 영문본이 우선합니다. 보다 자세한 내용은 이 페이지를 방문하시기 바랍니다.

문제 신고

PHP 스크립트를 사용하여 배포 기록

REST API 또는 PHP 프로그램 또는 스크립트를 통해 애플리케이션 배포에 대한 정보를 New Relic에 보낼 수 있습니다. 스크립트를 통해 배포를 기록하려면 PHP 설치에 libcurl 을 사용할 수 있어야 합니다.

스크립트 사용자 정의

PHP 애플리케이션으로 배포를 기록하도록 예제 스크립트 를 사용자 지정합니다.

  1. PHP 설치에 libcurl 이 설치되어 있는지 확인하십시오.

  2. 아래 예제 스크립트 를 텍스트 편집기에 복사합니다.

  3. $apikey 줄에 New Relic API 키 를 지정합니다.

  4. New Relic이 배포를 기록할 앱을 지정합니다.

    • 기존 New Relic 앱 ID 를 지정합니다.

      또는

    • 기존 New Relic for PHP 앱에 해당하는 $app_name 를 지정합니다. 앱 이름을 통해 앱을 지정하는 경우 스크립트의 데이터 문자열 섹션에서 다음 줄의 주석 처리를 제거해야 합니다.

      $dep_dat = "deployment[app_name]=".$app_name;
  5. 선택 사항: $dep_description , $dep_change , $dep_user$dep_rev 값을 사용자 지정하여 배포에 대한 추가 세부정보를 기록합니다. 이러한 값을 사용자 정의하는 경우 스크립트의 데이터 문자열 섹션에서 해당 행의 주석 처리를 제거해야 합니다. 예를 들어, 스크립트에 사용자 이름을 기록하려면 데이터 문자열 섹션에서 다음 줄의 주석 처리를 제거하십시오.

    $dep_dat = $dep_dat."&deployment[user]=".$dep_user;
  6. 스크립트를 저장합니다.

  7. 배포 프로세스 중에 스크립트를 호출합니다.

예제 스크립트

주의

주의: 이것은 일반적인 예이며 시스템 구성에 맞게 사용자 정의 해야 합니다.

#!/usr/bin/php
<?php
#Deployment
# Assumes the availability of libcurl in the PHP environment.
#Make your changes here:
$apikey = "{INSERT YOUR API KEY HERE}";
#Specify an existing New Relic app name OR app ID
#$app_name = "{INSERT YOUR APPLICATION NAME HERE}";
$app_id = "{INSERT YOUR APPLICATION ID HERE}";
$dep_description = "This is your app id deployment";
#$dep_change = "This is a change log entry";
#$dep_user = "This is the user entry";
#$dep_rev = "This is a version number";
#compose the data string for curl
#$dep_dat = "deployment[app_name]=".$app_name;
$dep_dat = "deployment[app_id]=".$app_id;
$dep_dat = $dep_dat."&deployment[description]=".$dep_description;
#$dep_dat = $dep_dat."&deployment[changelog]=".$dep_change;
#$dep_dat = $dep_dat."&deployment[user]=".$dep_user;
#$dep_dat = $dep_dat."&deployment[revision]=".$dep_rev;
#There should be no changes necessary beyond this point
#deployment url at New Relic
$url = "https://api.newrelic.com/deployments.xml";
#Create header info
$header = array("x-api-key:".$apikey);
#initialize curl
$ch = curl_init();
curl_setopt ($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header );
curl_setopt ($ch, CURLOPT_POSTFIELDS, $dep_dat );
# Make the curl call for deployment
$http_result = curl_exec ($ch);
$error = curl_error($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
#close curl
curl_close ($ch);
#output status
vprintf ("Code %s\n", $http_code);
vprintf ("Results %s\n", $http_result);
if ($error) {
vprintf ("Error %s\n",$error);
}
?>
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.