PHP,如何从apache服务器延长等待时间以显示进度条

时间:2014-02-11 18:40:38

标签: javascript php apache

问题是,我使用SOAP返回信息,差不多有75150或更多记录,我需要插入sql server,这需要很长时间。

我正在使用几个进度条,所有这些在一定时间内正常工作,后来停止,我意识到问题是等待服务器时间,进度条工作正常,当服务器保持“等待localhost”,但是这消失了,前进和后退箭头被启用,进度条不起作用,但在后面,插入继续。

存在一些方法来实现这种方法。

CODE

  ini_set ( "memory_limit", "512M" ); // Aumento de memoria
  ini_set ( 'max_execution_time', 15400 ); // minutos
  ini_set ( 'soap.wsdl_cache_enabled', 1 ); // original 0
  ini_set ( 'soap.wsdl_cache_ttl', '86400' ); // original 0, suggest 3600
  ini_set('output_buffering', 0);

 public function processOrdersDetails(SoapClient $clienteSOAP) {

        echo "Consultando...\n";

        $response = $clienteSOAP->viewAllOrdersDataDetails ( array (
                'val' => 'somevaluehere',
                'val2' => 'anothervaluehere' 
        ) );

        $size = count ( ( array ) $response->Result->DetailsData );

        for($i = 0; $i < $size; $i ++) {

            $orderd = new \entidad\orderDetails ();
            $percent =  ($i / $size * 100)  . "%";

            // Javascript for updating the progress bar and information
            echo '<script language="javascript">
                    document.getElementById("progress").innerHTML="<div style=\"width:' . $percent . ';background-color:#ddd;\">&nbsp;</div>";
                    document.getElementById("information").innerHTML="' . $i . ' row(s) processed.";
                    </script>';

            // This is for the buffer achieve the minimum size in order to flush data
            echo str_repeat ( ' ', 1024 * 64 );

            // Send output to browser immediately
            flush ();

            // Sleep one second so we can see the delay
            sleep ( 1 );

            $orderd->orderID = $response->Result->DetailsData [$i]->orderID;

            // Insert
            $logorderd->insert ( $orderd );
            // fin
        }

        echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
    }

0 个答案:

没有答案