用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3870|回复: 3
收起左侧

数据读取不同步问题

[复制链接]
发表于 2008-5-5 16:41:19 | 显示全部楼层 |阅读模式
我这有三个页面
A->FTP发送文件(php执行)边发边存SESSION
B->读SESSION-输出JS
C->AJAX调用A(1次),B页面,显示进度
问题,
1、为什么调用C执行A,B后,进度显示不出来,要执行完了后才显示全不进度
2、为什么执行A时,几乎同时执行B,要等到A的文件发送完了后才显示
代码

A- >
<?php
session_start();
if(!defined('BASE_URL'))die('Hacking Attmpt!');
set_time_limit(600);
$width = 652;   
$total = 1000;
$pix = $width / $total;
$progress = 10;
//echo '<meta http-equiv="Content-Type" c />';

      $data = array(
         'host' => '127.0.0.1',
         'user' => 'bizman',
         'pass' => 'jacson',
         'port'=>21
        );

$script = <<<eot
<script language="JavaScript">
updateProgress("Begain connect ftp server....", 1);
</script>
eot;
$_SESSION['sent'] = $script."\n";

if(FALSE===($ftp = new Ostenia_File_Remote_Ftp($data))){
$script = <<<eot
<script language="JavaScript">
updateProgress("Can not connect ftp server....", 1);
</script>
eot;
$_SESSION['sent'] = $script."\n";exit;
}
try{
         $ftppath = '/ajaxtest/';//要创建的目录
         $path = ROOT_PATH.'data/wp/wp_extract_data/wp/2.3.2wordpress-2.3.2/wordpress/';
            $source = ftp_array($path);
   $tt = count($source);
            foreach ($source as $item) {
              $fp = array(
                    'path'=>$item['path'],
                    'realname'=>$item['realname'],
              );
          $f = $fp['path'].$fp['realname'];//得到FTP路径
                $e = explode("$path",$f);
              $e = array_pop($e);#转义路径
              $clientftp = $ftppath;//client ftp path
                $realyftppath = $clientftp.$e; //FTP上传后的文件名
                $e = basename($f);// 获得文件名
                $ftp->upload($fp, $realyftppath);//sent file to severs
                $pix = $width/$tt;
       $progress += $pix;
$length = min($width, intval($progress));
$script = <<<eot
<script language="JavaScript">
updateProgress("Senting $e ,please waiting....", $length);
</script>
eot;
                $_SESSION['sent']= $script."\n";
///是不是这地方写的问题
   }#end foreach
   //print_r($_SESSION['sent']);
}catch (Ostenia_File_Protocol_Exception $e) {
$pix = $width/$tt;
$progress += $pix;
$length = min($width, intval($progress));
$script = <<<eot
<script language="JavaScript">
updateProgress("system error", $length);
</script>
eot;
exit;
}
$ftp->close();//关闭FTP
                  $pix = $width/$tt;
         $progress += $pix;
$length = min($width, intval($progress));
$script = <<<eot
<script language="JavaScript">
updateProgress("Finished sent all the files.", $width);
</script>
eot;
                $_SESSION['sent'] = $script."\n";
?>

B
  if((isset($_SESSION))&&(!empty($_SESSION))){
    header("Content-type: text/html; charset=utf-8");
    //header('Content-type: text/javascript');
    print_r($_SESSION['sent']);
    session_unset('sent');
  }else{
   header("Status: 404 Not Found");
   exit;
  }

C-》


<?php
$width = 652;   
$total = 1000;
$pix = $width / $total;
$progress = 10;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" c />
        <title>Javascript Progress Bar Demo - Gracecode.com</title>
        <script type="text/javascript" src="/js/jquery.js"></script>
        <script type="text/javascript">
   function loadpage(){
    $.get("/load.php?p=sent");
    alert('LOAD Page is ok');
   }
   function loadsession(Progress){
    if(Progress){
     $("#show").load("/load.php?p=load");
    }
   }
            var i = 0;
            function doProgress() {
                if (i > 10) {
                    alert("Progress Bar Finished!");
                    return;
                }
                if (i <= 10) {
      setTimeout("doProgress()", 500);
                    loadsession(i);
                    i++;
                }
            }
   $(document).ready(function() {
       loadpage();
    doProgress();
            });
        </script>
     <script language="JavaScript">
   <!--
   function updateProgress(sMsg, iWidth)
   {
       document.getElementById("status").innerHTML = sMsg;
       document.getElementById("progress").style.width = iWidth + "px";
       document.getElementById("percent").innerHTML = parseInt(iWidth / <?php echo $width; ?> * 100) + "%";
    }
  //-->
   </script>  
</head>
<body>
</head>
<body>
<div style="margin:4px 4px 0px 20px;  padding: 8px; color:#FF0000; font-size:13px; font-weight:bold;border: 1px solid gray; margin-left:14px;background: #EAEAEA; width: <?php echo $width+8; ?>px">
   <div style="text-align:center"><font color="#FF0000">发送文件中...</font></div>
   <div style="padding: 0; background-color: white; border: 1px solid navy; width: <?php echo $width; ?>px">
       <div id="progress" style="padding: 0; background-color: #FFCC66; border: 0; width: 0px; text-align: center;  height: 16px"></div>            
   </div>
   <div id="status"> </div>
   <div id="percent" style="position: relative; top: -30px; text-align: center; font-weight: bold; font-size: 8pt">0%</div>
</div>
<div id ="show"></div>
</body>
</html>

[ 本帖最后由 bizman 于 2008-5-5 16:58 编辑 ]
 楼主| 发表于 2008-5-6 09:05:14 | 显示全部楼层
没人看,这也太...
算了,偶自己解决
 楼主| 发表于 2008-5-7 14:21:38 | 显示全部楼层
偶自己解决了
偶放在BLOG上去了
谁愿看就去看吧
直接运行是运行不起的
http://v2.getroad.cn/blog/?action=show&id=423&page=1
原理也是那样
边写边读
只是方式不一样
过去是写到session里去的
现在是直接创建一个文件
然后间隔5秒或者更少去调用

有意的可以去看看
发表于 2008-5-7 15:04:44 | 显示全部楼层
我顶~~~佩服楼主的钻研精神!!

本版积分规则