从PHP运行gcloud命令

时间:2015-11-02 05:59:57

标签: php google-cloud-platform

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

shell_exec('ls')

它提供了文件和文件夹列表。

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

我正在使用

shell_exec('gcloud compute instances list')

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

有人可以告诉我如何实现这个目标吗?

1 个答案:

答案 0 :(得分:3)

您可以考虑直接使用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