等到完成加载 curl 可执行文件,然后显示



大家好,提前感谢您的阅读,我在使用 curl php 时遇到问题,我做了一个文件.php事实上,文件工作正常,我唯一的问题是,当我提取数据时,它至少需要 20 秒,我想加快该过程或制作一些东西来加载curl_exec并确保它已完全加载并显示它,因为我有一个问题,即使是正在加载的表中的某些图像也没有出现。任何帮助将不胜感激。

<?php
ini_set('max_execution_time', 300);
$ref = $_SERVER['HTTP_REFERER'];
$values = parse_url($ref);
$pedazo = explode("/", $ref);
switch ($pedazo[4]) {
    case 'page-bajio.php':
        // Initialise a cURL object
        $ch = curl_init();
        // Set url and other options
        curl_setopt($ch, CURLOPT_URL, "http://www.directoriomex.com.mx/basebaj.asp");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_NOBODY, 0);
        // Get the page contents
        $output = curl_exec($ch);
        $info = curl_getinfo($ch);
        echo "Fueron {$info['total_time']} segundos para la url {$info['url']}<br>" . 
             $info['content_type']. "<br>" . 
             $info['http_code'] . "<br>" .
             $info['header_size'] . "<br>" . 
             $info['request_size'] . "<br>" . 
             $info['filetime'] . "<br>" . 
             $info['ssl_verify_result'] . "<br>" . 
             $info['redirect_count'] . "<br>" . 
             $info['total_time'] . "<br>" . 
             $info['namelookup_time'] . "<br>" . 
             $info['connect_time'] . "<br>" . 
             $info['pretransfer_time'] . "<br>" . 
             $info['size_upload'] . "<br>" . 
             $info['size_download'] . "<br>" . 
             $info['speed_download'] . "<br>" . 
             $info['speed_upload'] . "<br>" . 
             $info['download_content_length'] . "<br>" . 
             $info['upload_content_length'] . "<br>" . 
             $info['starttransfer_time'] . "<br>" . 
             $info['redirect_time'] . "<br>";
        curl_close($ch);
        echo $output;
        break;
    default:
        header("location:../initializr");
        break;
}

据我了解您的问题,您希望在服务器"完全加载"页面之前防止页面的某些部分显示。

尝试在脚本开头将隐式刷新设置为 off(请参阅此处的文档)

ob_implicit_flush(false);

您还可以设置输出缓冲区并在之后手动刷新它,如下所示:

ob_start();
//your script goes here
ob_end_flush();

在此处找到输出缓冲的文档

相关内容

最新更新