{"id":57535,"date":"2025-03-01T14:25:54","date_gmt":"2025-03-01T06:25:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/57535\/"},"modified":"2025-03-01T14:25:54","modified_gmt":"2025-03-01T06:25:54","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8vultr-api%e7%9a%84php%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/57535\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Vultr API\u7684PHP\u793a\u4f8b"},"content":{"rendered":"<h2>\u76ee\u5f55<\/h2>\n<ol>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ol>\n<h2>Vultr API\u7b80\u4ecb<\/h2>\n<p>Vultr\u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u7684\u4e91\u8ba1\u7b97\u5e73\u53f0\uff0c\u63d0\u4f9b\u4e86\u5168\u9762\u7684API\u63a5\u53e3\uff0c\u65b9\u4fbf\u5f00\u53d1\u8005\u901a\u8fc7\u7f16\u7a0b\u7ba1\u7406\u4e91\u8d44\u6e90\u3002_Vultr API_\u63d0\u4f9b\u4e86\u591a\u79cd\u529f\u80fd\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u521b\u5efa\u3001\u7ba1\u7406\u548c\u5220\u9664\u5b9e\u4f8b\u3001\u76d1\u63a7\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u4ee5\u53ca\u8fdb\u884c\u8d26\u6237\u7ba1\u7406\u7b49\u3002\u4f7f\u7528API\u53ef\u4ee5\u6781\u5927\u63d0\u9ad8\u8d44\u6e90\u7ba1\u7406\u7684\u7075\u6d3b\u6027\u548c\u6548\u7387\u3002<\/p>\n<h2>\u73af\u5883\u51c6\u5907<\/h2>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u4f60\u7684\u73af\u5883\u5df2\u7ecf\u51c6\u5907\u597d\uff1a<\/p>\n<ul>\n<li><strong>PHP 7.2\u53ca\u4ee5\u4e0a\u7248\u672c<\/strong><\/li>\n<li><strong>Composer<\/strong>\uff08\u7528\u4e8e\u7ba1\u7406PHP\u4f9d\u8d56\uff09<\/li>\n<li><strong>cURL\u6269\u5c55<\/strong>\uff08\u786e\u4fddPHP\u652f\u6301cURL\uff09<\/li>\n<\/ul>\n<h2>Vultr API\u7684\u57fa\u672c\u4f7f\u7528<\/h2>\n<p>\u4f7f\u7528Vultr API\u7684\u7b2c\u4e00\u6b65\u662f\u83b7\u53d6API\u5bc6\u94a5\u3002\u4f60\u53ef\u4ee5\u5728Vultr\u7684\u63a7\u5236\u9762\u677f\u4e2d\u627e\u5230\u5e76\u751f\u6210\u4f60\u7684API\u5bc6\u94a5\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5728PHP\u4e2d\u8bbe\u7f6e\u8bf7\u6c42\u5934\u548c\u57fa\u672c\u7684\u8bf7\u6c42\u65b9\u6cd5\u3002<\/p>\n<h3>\u83b7\u53d6API\u5bc6\u94a5<\/h3>\n<ol>\n<li>\u767b\u5f55Vultr\u63a7\u5236\u9762\u677f\u3002<\/li>\n<li>\u70b9\u51fbAPI\u83dc\u5355\u3002<\/li>\n<li>\u751f\u6210\u4e00\u4e2a\u65b0\u7684API\u5bc6\u94a5\u5e76\u590d\u5236\u3002<\/li>\n<\/ol>\n<h3>\u8bbe\u7f6e\u8bf7\u6c42\u5934<\/h3>\n<p>\u4f7f\u7528cURL\u53d1\u9001\u8bf7\u6c42\u65f6\uff0c\u9700\u8981\u8bbe\u7f6e\u8bf7\u6c42\u5934\u6765\u5305\u542bAPI\u5bc6\u94a5\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u8bf7\u6c42\u5934\u683c\u5f0f\uff1a<\/p>\n<p>php $headers = [ \u2018Content-Type: application\/json\u2019, \u2018Authorization: Bearer YOUR_API_KEY\u2019, ];<\/p>\n<h2>Vultr API PHP\u793a\u4f8b\u4ee3\u7801<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684Vultr API PHP\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b\uff1a<\/p>\n<p>php \/\/ \u8bbe\u7f6eAPI\u5bc6\u94a5\u548c\u8bf7\u6c42URL $apiKey = \u2018YOUR_API_KEY\u2019; $url = \u2018https:\/\/api.vultr.com\/v2\/instances\u2019;<\/p>\n<p>\/\/ \u521d\u59cb\u5316cURL\u4f1a\u8bdd $ch = curl_init();<\/p>\n<p>\/\/ \u8bbe\u7f6ecURL\u9009\u9879 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ \u2018Content-Type: application\/json\u2019, \u2018Authorization: Bearer \u2018 . $apiKey, ]);<\/p>\n<p>\/\/ \u521b\u5efa\u5b9e\u4f8b\u6240\u9700\u7684JSON\u6570\u636e $data = json_encode([ \u2018region\u2019 =&gt; \u2018newark\u2019, \u2018plan\u2019 =&gt; \u2018vc2-1c-1gb\u2019, \u2018os_id\u2019 =&gt; 270, ]);<\/p>\n<p>curl_setopt($ch, CURLOPT_POSTFIELDS, $data);<\/p>\n<p>\/\/ \u6267\u884ccURL\u8bf7\u6c42\u5e76\u83b7\u53d6\u54cd\u5e94 $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);<\/p>\n<p>\/\/ \u5173\u95edcURL\u4f1a\u8bdd curl_close($ch);<\/p>\n<p>\/\/ \u8f93\u51fa\u7ed3\u679c if ($httpCode == 200) { echo \u2018\u5b9e\u4f8b\u521b\u5efa\u6210\u529f\uff1a\u2019 . $response; } else { echo \u2018\u9519\u8bef\uff1a\u2019 . $response;}<\/p>\n<h2>\u5e38\u89c1\u64cd\u4f5c\u793a\u4f8b<\/h2>\n<h3>\u83b7\u53d6\u6240\u6709\u5b9e\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u83b7\u53d6\u5f53\u524d\u8d26\u6237\u4e0b\u7684\u6240\u6709\u5b9e\u4f8b\uff1a<\/p>\n<p>php $url = \u2018https:\/\/api.vultr.com\/v2\/instances\u2019; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ \u2018Content-Type: application\/json\u2019, \u2018Authorization: Bearer \u2018 . $apiKey, ]); $response = curl_exec($ch); curl_close($ch);<\/p>\n<p>echo \u2018\u5f53\u524d\u5b9e\u4f8b\uff1a\u2019 . $response;<\/p>\n<h3>\u5220\u9664\u5b9e\u4f8b<\/h3>\n<p>\u8981\u5220\u9664\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<p>php $instanceId = \u2018INSTANCE_ID\u2019; $url = \u2018https:\/\/api.vultr.com\/v2\/instances\/\u2019 . $instanceId; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, \u2018DELETE\u2019); curl_setopt($ch, CURLOPT_HTTPHEADER, [ \u2018Content-Type: application\/json\u2019, \u2018Authorization: Bearer \u2018 . $apiKey, ]); $response = curl_exec($ch); curl_close($ch);<\/p>\n<p>echo \u2018\u5220\u9664\u7ed3\u679c\uff1a\u2019 . $response;<\/p>\n<h2>\u9519\u8bef\u5904\u7406\u4e0e\u8c03\u8bd5<\/h2>\n<p>\u5728\u4f7f\u7528Vultr API\u65f6\uff0c\u5904\u7406\u9519\u8bef\u548c\u8c03\u8bd5\u975e\u5e38\u91cd\u8981\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u6765\u6355\u83b7\u548c\u5904\u7406\u9519\u8bef\uff1a<\/p>\n<ul>\n<li>\u68c0\u67e5HTTP\u72b6\u6001\u7801\uff0c\u786e\u4fdd\u8bf7\u6c42\u6210\u529f\uff08200 OK\uff09\u3002<\/li>\n<li>\u8f93\u51faAPI\u8fd4\u56de\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u4ee5\u4fbf\u8fdb\u884c\u5206\u6790\u3002<\/li>\n<li>\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u8003\u8651\u4f7f\u7528\u65e5\u5fd7\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h2>FAQ<\/h2>\n<h3>Vultr API\u7684\u6700\u5927\u8bf7\u6c42\u901f\u7387\u662f\u591a\u5c11\uff1f<\/h3>\n<p>Vultr API\u7684\u6700\u5927\u8bf7\u6c42\u901f\u7387\u4e3a\u6bcf\u5206\u949f60\u6b21\u3002\u8d85\u8fc7\u8be5\u9650\u5236\u540e\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4429 Too Many Requests\u9519\u8bef\u3002<\/p>\n<h3>Vultr API\u662f\u5426\u652f\u6301PHP SDK\uff1f<\/h3>\n<p>\u867d\u7136Vultr\u6ca1\u6709\u5b98\u65b9\u7684PHP SDK\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u6216\u81ea\u884c\u5c01\u88c5API\u8bf7\u6c42\u6765\u7b80\u5316\u4f7f\u7528\u3002<\/p>\n<h3>\u5982\u4f55\u83b7\u5f97Vultr\u7684API\u6587\u6863\uff1f<\/h3>\n<p>\u4f60\u53ef\u4ee5\u5728Vultr\u7684\u5b98\u65b9\u7f51\u7ad9\u627e\u5230API\u6587\u6863\uff0c\u7f51\u5740\u4e3a\u3002<\/p>\n<h3>\u4f7f\u7528Vultr API\u9700\u8981\u989d\u5916\u8d39\u7528\u5417\uff1f<\/h3>\n<p>\u4f7f\u7528Vultr API\u672c\u8eab\u662f\u514d\u8d39\u7684\uff0c\u4f46\u6240\u6709\u901a\u8fc7API\u521b\u5efa\u7684\u8d44\u6e90\uff08\u5982\u5b9e\u4f8b\u3001\u5b58\u50a8\u7b49\uff09\u90fd\u5c06\u4ea7\u751f\u6b63\u5e38\u7684\u4f7f\u7528\u8d39\u7528\u3002<\/p>\n<h3>\u5982\u4f55\u89e3\u51b3Vultr API\u7684\u8ba4\u8bc1\u9519\u8bef\uff1f<\/h3>\n<p>\u786e\u4fddAPI\u5bc6\u94a5\u7684\u683c\u5f0f\u6b63\u786e\uff0c\u4e14\u5728\u8bf7\u6c42\u5934\u4e2d\u8bbe\u7f6e\u4e86\u6b63\u786e\u7684Authorization\u5b57\u6bb5\u3002\u5982\u679c\u95ee\u9898\u4f9d\u65e7\uff0c\u8bf7\u5c1d\u8bd5\u751f\u6210\u65b0\u7684API\u5bc6\u94a5\u3002<\/p>\n<hr>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u5185\u5bb9\uff0c\u76f8\u4fe1\u4f60\u5bf9\u5982\u4f55\u4f7f\u7528_Vultr API_\u8fdb\u884cPHP\u7f16\u7a0b\u6709\u4e86\u66f4\u6df1\u5165\u7684\u4e86\u89e3\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u5145\u5206\u5229\u7528API\u7684\u529f\u80fd\u5c06\u5927\u5927\u63d0\u5347\u4e91\u8d44\u6e90\u7684\u7ba1\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 Vultr API\u7b80\u4ecb Vultr\u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u7684\u4e91\u8ba1\u7b97\u5e73\u53f0\uff0c\u63d0\u4f9b\u4e86\u5168\u9762\u7684API\u63a5\u53e3\uff0c\u65b9\u4fbf\u5f00\u53d1\u8005\u901a\u8fc7\u7f16\u7a0b\u7ba1\u7406\u4e91\u8d44\u6e90\u3002_Vultr API_\u63d0\u4f9b\u4e86\u591a\u79cd\u529f\u80fd\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u521b\u5efa\u3001\u7ba1\u7406\u548c\u5220\u9664\u5b9e\u4f8b\u3001\u76d1\u63a7\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u4ee5\u53ca\u8fdb\u884c\u8d26\u6237\u7ba1\u7406\u7b49\u3002\u4f7f\u7528API\u53ef\u4ee5\u6781\u5927\u63d0\u9ad8\u8d44\u6e90\u7ba1\u7406\u7684\u7075\u6d3b\u6027\u548c\u6548\u7387\u3002 \u73af\u5883\u51c6\u5907 \u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u4f60\u7684\u73af\u5883\u5df2\u7ecf\u51c6\u5907\u597d\uff1a PHP 7.2\u53ca\u4ee5\u4e0a\u7248\u672c Composer\uff08\u7528\u4e8e\u7ba1\u7406PHP\u4f9d\u8d56\uff09 cURL\u6269\u5c55\uff08\u786e\u4fddPHP\u652f\u6301cURL\uff09 Vultr API\u7684\u57fa\u672c\u4f7f\u7528 \u4f7f\u7528Vultr API\u7684\u7b2c\u4e00\u6b65\u662f\u83b7\u53d6API\u5bc6\u94a5\u3002\u4f60\u53ef\u4ee5\u5728Vultr\u7684\u63a7\u5236\u9762\u677f\u4e2d\u627e\u5230\u5e76\u751f\u6210\u4f60\u7684API\u5bc6\u94a5\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5728PHP\u4e2d\u8bbe\u7f6e\u8bf7\u6c42\u5934\u548c\u57fa\u672c\u7684\u8bf7\u6c42\u65b9\u6cd5\u3002 \u83b7\u53d6API\u5bc6\u94a5 \u767b\u5f55Vultr\u63a7\u5236\u9762\u677f\u3002 \u70b9\u51fbAPI\u83dc\u5355\u3002 \u751f\u6210\u4e00\u4e2a\u65b0\u7684API\u5bc6\u94a5\u5e76\u590d\u5236\u3002 \u8bbe\u7f6e\u8bf7\u6c42\u5934 \u4f7f\u7528cURL\u53d1\u9001\u8bf7\u6c42\u65f6\uff0c\u9700\u8981\u8bbe\u7f6e\u8bf7\u6c42\u5934\u6765\u5305\u542bAPI\u5bc6\u94a5\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u8bf7\u6c42\u5934\u683c\u5f0f\uff1a php $headers = [ \u2018Content-Type: application\/json\u2019, \u2018Authorization: Bearer YOUR_API_KEY\u2019, ]; Vultr API PHP\u793a\u4f8b\u4ee3\u7801 \u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684Vultr API PHP\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b\uff1a php \/\/ \u8bbe\u7f6eAPI\u5bc6\u94a5\u548c\u8bf7\u6c42URL $apiKey = \u2018YOUR_API_KEY\u2019; $url = \u2018https:\/\/api.vultr.com\/v2\/instances\u2019; \/\/ \u521d\u59cb\u5316cURL\u4f1a\u8bdd $ch = curl_init(); \/\/ \u8bbe\u7f6ecURL\u9009\u9879 curl_setopt($ch, CURLOPT_URL, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-57535","post","type-post","status-publish","format-standard","hentry","category-vpn"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/57535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=57535"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/57535\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=57535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=57535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=57535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}