2013-04-23 3 views
2

http://w3shaman.com/article/php-progress-bar-script에서 예제를 실행하려고합니다.스크립트 완료 후 PHP 진행률 막대가 표시됩니다.

나는 windows에서 quickPHP을 사용하고 있습니다. 자습서 위의 라이브가 잘 실행중인 Demo 링크가 있습니다.

문제 :이 스크립트를 테스트 할 때

, 나는 PHP가 처리 할 경우에만 바 얻을. 나는 또한 jQuery UI 진행 막대를 사용하여 시도했지만 PHP는 진행률 표시 줄을 표시하기 전에 바쁘다가 갑자기 끝날 때 100 완료를 보여줍니다. 뭐가 잘못 되었 니 ? above link에서

코드 :

//At the beginning of your PHP file 
ob_start(); 
... 

그리고 :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> 
<html lang="en"> 
<head> 
    <title>Progress Bar</title> 
</head> 
<body> 
<!-- Progress bar holder --> 
<div id="progress" style="width:500px;border:1px solid #ccc;"></div> 
<!-- Progress information --> 
<div id="information" style="width"></div> 
<?php 
// Total processes 
$total = 10; 

// Loop through process 
for($i=1; $i<=$total; $i++){ 
    // Calculate the percentation 
    $percent = intval($i/$total * 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); 
} 

// Tell user that the process is completed 
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>'; 
?> 
</body> 
</html> 

답변

1

지금 당장 생각해 보면, Quick PHP는 여기에 명시된대로 중간 결과를 얻지 못하도록합니다 : http://www.zachsaw.com/forum/viewtopic.php?f=11&t=27&hilit=flush (저는 오래된 게시물이지만 QuickPHP에서 플러시 사용에 대한 최근 참조를 찾을 수 없습니다).

QuickPHP가 PHP의 출력을 처리하는 방식 때문에 전체 스크립트 실행이 완료 될 때만 결과를 보냅니다. PHP 스크립트가 실행 중일 때 스크립트가 웹 브라우저로 데이터를 보낼 수있는 가능성에 의존하기 때문에 바를 완성하는 이유입니다.

그래서 답은 바로 지금 그렇게 할 수 없다는 것입니다.

0

봅니다이 하나를 사용하는

ob_flush(); 
flush(); 

대신

flush(); 
+0

스크립트 실행 후 여전히 동일합니다. 갑자기 보여줍니다. – django

+0

그것은 아주 이상합니다. 그것은 나에게 잘 작동합니다. 나는 생각을 가지고있다 :'echo'를 사용하지 말아라.'...?>

+0

당신은 quickPHP를 사용하고 있습니까? – django

0

나는 내 작업과 비슷한 상황이었습니다. jquery, json을 사용하여 스크립트 실행 진행 상황을 확인했습니다. php 스크립트는 임시 파일의 상태를 기록합니다. 나는 그것에 대해 blogged 거기에 몇 가지 버그가있을 수 있지만 꽤 잘 수행 않습니다.

관련 문제