Php 读取多个url内容(file\u get\u contents或curl\u exec)导致脚本出现x循环

Php 读取多个url内容(file\u get\u contents或curl\u exec)导致脚本出现x循环,php,codeigniter,curl,file-get-contents,Php,Codeigniter,Curl,File Get Contents,我正在在线服务器(域网站)上运行Codeigniter、PHP7中的脚本。。从该URL读取的文本多次: 仅在s=(股票符号)中进行更改 我的问题是,如果我读取x URL,我的脚本将完成所有URL(符号)的读取 但它在一个不规则的x循环中多次重新启动。我不理解那种行为 最大执行时间为1500。没有错误出现,很多时候我只得到一个空白页 我在codeigniter/controller中的脚本: private function _get_current_yahoo_data($stock_sym

我正在在线服务器(域网站)上运行Codeigniter、PHP7中的脚本。。从该URL读取的文本多次:

仅在s=(股票符号)中进行更改

我的问题是,如果我读取x URL,我的脚本将完成所有URL(符号)的读取 但它在一个不规则的x循环中多次重新启动。我不理解那种行为

最大执行时间为1500。没有错误出现,很多时候我只得到一个空白页

我在codeigniter/controller中的脚本:

 private function _get_current_yahoo_data($stock_symbol) {

    $url = 'http://download.finance.yahoo.com/d/quotes.csv';
    // ---- Stock Symbol ----
    $url.= "?s=".$stock_symbol;
    $url.= "&f=d1ohgl1vs"; 

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    //curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $content = curl_exec($ch);
    curl_close($ch);    

    return $content;
 }  


 public function update_current_stocks_data() {

    $output = '';

    $import_date = date('Y-m-d H:i:s');
    $s1 = time();
    $data = $this->data;

    $stocks = $data['stocks'];

    foreach($stocks as $s) {

        $id_stock = $s->id;


        $stock_symbol = $s->symbol;

        $p1 = time();
        $raw_quote_data = $this->_get_current_yahoo_data($stock_symbol);
        $p2 = time();

        $output.= $id_stock.' ';
        $output.= ' __ Time: '.($p2 - $p1).' seconds<br>';;


    }


    $s2 = time();

    $output.= '<br>Execution Time: '.($s2 - $s1).' seconds';

    $this->stock_model->log($import_date, $output);

    $output.= '<br>';
    $output.= strlen($output);
    $data['output'] = $output;
    $this->load->view("simple_view", $data);

}   
private函数\u获取\u当前\u雅虎\u数据($stock\u符号){
$url='1http://download.finance.yahoo.com/d/quotes.csv';
//----股票符号----
$url.=“?s=”.$stock\u符号;
$url.=“&f=d1ohgl1vs”;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
//curl_setopt($ch,CURLOPT_头,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$content=curl\u exec($ch);
卷曲关闭($ch);
返回$content;
}  
公共功能更新\当前\库存\数据(){
$output='';
$import_date=日期('Y-m-d H:i:s');
$s1=时间();
$data=$this->data;
$stocks=$data['stocks'];
foreach(股票为$s){
$id\u stock=$s->id;
$stock_symbol=$s->symbol;
$p1=时间();
$raw\u quote\u data=$this->\u get\u current\u yahoo\u data($stock\u symbol);
$p2=时间();
$output.=$id_stock.';
$output.='uuu时间:'($p2-$p1)。'seconds
';; } $s2=时间(); $output.='
执行时间:'($s2-$s1)。'seconds'; $this->stock\u model->log($import\u date,$output); $output.='
'; $output.=strlen($output); $data['output']=$output; $this->load->view(“简单视图”、$data); }
我正在查看我的日志表(从函数日志填充),有几个日志行只启动了一次脚本

每个脚本都在大约100秒内完成,总共有259只股票
例如,如果我减少库存列表,那么就没有问题,脚本只运行一次。有趣的是,如果我每隔259次阅读一次脚本循环。

您可以在命令行界面或使用cron作业运行此循环。因为在浏览器模式下,脚本存在最大执行超时。如果您在linux redhat中运行,那么您必须更改selinux设置如果我启动phpinfo(),我看到max_execution_time(local)=1500selinux设置是比phpinfo详细信息更高级的控件