等到完成加载curl exec然后显示

时间:2014-01-03 02:38:59

标签: php parsing curl load

大家好,并提前感谢阅读,我遇到curl php的问题我做了一个file.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;
}

1 个答案:

答案 0 :(得分:2)

据我了解您的问题,您希望在服务器“完全加载”页面之前阻止您的页面显示。

尝试在脚本开头(see docs here

将隐式刷新设置为关闭
ob_implicit_flush(false);

你也可以设置一个输出缓冲区,然后手动冲洗它,如下所示:

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

输出缓冲的文档可以在 here

找到
相关问题