在一行中为 linux cronjob 包含多个 php 文件

我有很多基于 php 文件的动态图像。当我访问这些文件时,内容(图像)会更新。我使用这个命令行来访问 linux cronjob 中的 php 文件:


*/10 * * * * curl -q https://website.com/folder/A1-imageproduct1.php

*/10 * * * * curl -q https://website.com/folder/A1-imageproduct2.php

*/10 * * * * curl -q https://website.com/folder/A1-imageproduct3.php

我想使用单个命令行,因为它包含大量文件。我尝试使用以下代码创建一个 php 文件:


<?php

        foreach (glob("A1-*.php") as $name)


    {

        include($name);

    }

?>


但只包括第一个文件,其余的显然都被忽略了,无论是使用 linux cronjob 还是从我的网络浏览器访问该文件。


长风秋雁
浏览 148回答 2
2回答

海绵宝宝撒

如果你必须从 curl 打电话,你应该做这样的事情<?php&nbsp;$llamar = new class{&nbsp; &nbsp;public function curl($file){&nbsp; &nbsp; &nbsp;$ch = curl_init();&nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_URL, "https://website.com/folder/".$file);&nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_HEADER, 0);&nbsp; &nbsp; &nbsp;curl_exec($ch);&nbsp; &nbsp; &nbsp;curl_close($ch);&nbsp; &nbsp;}&nbsp;};&nbsp;foreach (glob("A1-*.php") as $name){&nbsp; &nbsp;$llamar->curl($name);&nbsp;}&nbsp;?>如果您不恢复所有文件,最好使用此类将“RUTE”更改为您的目录路径$llamar = new class{&nbsp; &nbsp; public function curl($file){&nbsp; &nbsp; &nbsp; $ch = curl_init();&nbsp; &nbsp; &nbsp; curl_setopt($ch, CURLOPT_URL, "https://website.com/folder/".$file);&nbsp; &nbsp; &nbsp; curl_setopt($ch, CURLOPT_HEADER, 0);&nbsp; &nbsp; &nbsp; curl_exec($ch);&nbsp; &nbsp; &nbsp; curl_close($ch);&nbsp; &nbsp; }&nbsp; };$archivo = new class{&nbsp; &nbsp; public function leer($carpeta)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $archivos = array();&nbsp; &nbsp; &nbsp; &nbsp; if (is_dir($carpeta)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($dir = opendir($carpeta)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (($archivo = readdir($dir)) !== false) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($archivo != '.' && $archivo != '..' && $archivo != '.htaccess') {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (file_exists($carpeta . '/' . $archivo)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!is_dir($carpeta . '/' . $archivo)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $archivos[] = $archivo;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closedir($dir);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return $archivos;&nbsp; &nbsp; }}&nbsp; $archivos = $archivo->leer("RUTE");&nbsp; for($i=0;$i<count($archivos);$i++){&nbsp; &nbsp; $llamar->curl($archivos[$i]);&nbsp; }

慕田峪4524236

我认为您的路径不正确,请添加相对路径试试看$cwd=getcwd();foreach (glob("$cwd/folder/A1-*.php") as $name)&nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; include($name);&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP