Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP curl脚本未关闭连接_Php_Curl - Fatal编程技术网

PHP curl脚本未关闭连接

PHP curl脚本未关闭连接,php,curl,Php,Curl,我的网站上有一个cron作业,它每隔一段时间就运行一次,下载文本文件的内容。直到今天早上,当我从我的网络主机收到一封电子邮件,说我已经用完了所有(分配的)进程时,一切都很顺利。他们把它缩小到这个文件,并告诉我修复它,因为它没有正确关闭。欢迎对这位php新手提供任何帮助 #!/usr/bin/php <?php // create curl resource $ch = curl_init(); // set url cur

我的网站上有一个cron作业,它每隔一段时间就运行一次,下载文本文件的内容。直到今天早上,当我从我的网络主机收到一封电子邮件,说我已经用完了所有(分配的)进程时,一切都很顺利。他们把它缩小到这个文件,并告诉我修复它,因为它没有正确关闭。欢迎对这位php新手提供任何帮助

#!/usr/bin/php

<?php
        // create curl resource
        $ch = curl_init();

        // set url
        curl_setopt($ch, CURLOPT_URL, "http://www.address.com/textfile.txt");

        //return the transfer as a string
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        //$output contains the output string
        $output = curl_exec($ch);

        // We need to check whether the data is valid.
        // We check for the 'Client Error' string
        // inside the output data.  If it exists, we don't want
        // to overwrite the previous (good) data.

        if (strpos($output,'Client Error') !== false) {

            echo $output;
                //echo 'Client Error, no data.';

        }else{

            $outputFile = '/home/hostingacct/public_html/outputTextFile.txt';

            $fh = fopen($outputFile,'w') or die("can't open");
            fwrite($fh,$output);
            fclose($fh);
        }

        // close curl resource to free up system resources
        curl_close($ch);

?>
当我之前发布我的问题时,我让我的网络主机立即删除所有进程,因为它阻止了我的网站。问题在2个月后再次出现,进程仍在运行,等等。我根据Antoan运行了ps xauf,结果如上所示


看起来问题从12日开始,持续了两天。有人能解释一下这是怎么发生的吗?在那些有问题的日子里,这似乎发生在午夜之后。这是否可能是因为服务器(通过cURL)无法访问——导致php脚本无法退出?谢谢大家。

这很可能是错误的假设。
您有ssh访问此主机的权限吗

如果是,请执行
ps xuaf
,并检查存在哪些真正的进程

如果你把名单贴在这里,我们将能为你提供更多帮助

更新 看起来像是某种沟通问题。你能加上这些吗

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // Setting the amount of time (in seconds) before the request times out
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Setting the maximum amount of time for cURL to execute queries 

如果需要,请调整计时。

尽管我当时无法尝试,但2个月后我遇到了同样的问题,我已使用ps xuaf的输出编辑了我的原始问题。谢谢你的帮助。非常感谢。我会让你知道的。
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // Setting the amount of time (in seconds) before the request times out
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Setting the maximum amount of time for cURL to execute queries