gpt4 book ai didi

php - 从 PHP 运行 gcloud 命令

转载 作者:行者123 更新时间:2023-12-01 17:49:59 25 4
gpt4 key购买 nike

我们可以使用 shell_exec() 命令从 PHP 运行 shell 命令。当我尝试运行时

shell_exec('ls')

它给出文件和文件夹的列表。

我想使用 shell_exec 获取 Google Cloud 中的实例列表。

我正在使用

shell_exec('gcloud compute instances list')

它不会产生任何结果。当我在终端上运行相同的命令“gcloud 计算实例列表”时,它会显示项目下的所有实例。

谁能告诉我如何实现这一目标?

最佳答案

您可以考虑直接使用 REST API。 Gcloud调用相同的API。 https://cloud.google.com/compute/docs/reference/latest/instances/list

Google 提供了一个封装 REST API 的 PHP 客户端库: https://cloud.google.com/compute/docs/api/libraries#google_apis_php_client_library

关于php - 从 PHP 运行 gcloud 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33471584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com