繁体   English   中英

如何编写PHP代码来执行两个函数

[英]How to write PHP code to execute two functions

我有这个PHP脚本(用于Docker远程API),我用它来“远程”停止容器:

<?php

$cid = trim(file_get_contents('cid'));
echo "$cid\n";

function httpPost($url)
{
    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POST, true);

    $output=curl_exec($ch);

    curl_close($ch);
    return $output;
}

$url = "http://172.17.0.1:2375/containers/$cid/stop?t=5";
echo "$url\n";
echo httpPost($url)

?>

有用! 但我想让这段代码“停止” 两个 docker容器,而不只是一个。

我在考虑这样的事情:

$cid = trim(file_get_contents('cid'));
$pid = trim(file_get_contents('pid'));

那么代码的其余部分将如何显示,以便我们停止它们?

切换这部分:

$url = "http://172.17.0.1:2375/containers/$cid/stop?t=5";
echo "$url\n";
echo httpPost($url)

对此

$url1 = "http://172.17.0.1:2375/containers/$cid/stop?t=5";
$url2 = "http://172.17.0.1:2375/containers/$pid/stop?t=5";

echo httpPost($url1);
echo httpPost($url2);

这就是你如何基本完成它。 可以创建更复杂的结构。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM