Page 1 of 1

php apc...another nightmare...any insight highly appreciated

Posted: Sat Jan 09, 2010 9:09 pm
by scarface222
Starting my first web site has been a huge challenge, given I am relatively new to programming since I keep running into new problems. I have another concern regarding the php apc extension. I currently was using an upload script but it did not work, the bar stays frozen. I decided to try another one to make sure, the bar stays frozen...You guys usually provide some pretty useful insight that helps me learn more about what I am doing so I decided to post the problem for anyone experienced enough to give me some advice. Any insight from you guys is highly appreciated...Thanks in advance...

these are my apc settings according to the php ini file, and yes it does show up in php info(), it seems operational, except for the fact, no upload scripts work to show the progress bar, the bar freezes at the start.

extension=apc.so
apc.enabled=1
apc.max_file_size=10M
apc.shm_segments=1
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.rfc1867=1
apc.enable_cli=1

this is my script...There is some javascript in it, but my main problem is php apc. I feel there is some sort of issue with it or my bar would work.

Code: Select all

<?php
if($_SERVER['REQUEST_METHOD']=='POST') {
  $status = apc_fetch('upload_'.$_POST['APC_UPLOAD_PROGRESS']);
  $status['done']=1;
  echo json_encode($status);
  exit;
} else if(isset($_GET['progress_key'])) {
  $status = apc_fetch('upload_'.$_GET['progress_key']);
  echo json_encode($status);
  exit;
}
?>

Code: Select all

<html>
<head>
<script type="text/javascript" src="/yui/yahoo.js"></script>
<script type="text/javascript" src="/yui/event.js"></script>
<script type="text/javascript" src="/yui/dom.js"></script>
<script type="text/javascript" src="/yui/animation.js"></script>
<script type="text/javascript" src="/yui/dragdrop.js"></script>
<script type="text/javascript" src="/yui/connection.js"></script>
<script type="text/javascript" src="/yui/container.js"></script>
<link rel="stylesheet" type="text/css" href="/yui/build/container/assets/container.css" />
<script type="text/javascript">
var fN = function callBack(o) {
  var resp = eval('(' + o.responseText + ')');
  var rate = parseInt(resp['rate']/1024);
  if(resp['cancel_upload']) {
    txt="Cancelled after "+resp['current']+" bytes!"; 
  } else {
    txt=resp['total']+" bytes uploaded!";
  }
  txt += "<br>Upload rate was "+rate+" kbps.";
  document.getElementById('pbar').style.width = '100%';
  document.getElementById('ppct').innerHTML = "100%";
  document.getElementById('ptxt').innerHTML = txt;
  setTimeout("progress_win.hide(); window.location.reload(true);",2000);
}
var callback = { upload:fN }
 
var fP = function callBack(o) {
  var resp = eval('(' + o.responseText + ')');
  if(!resp['done']) { 
    if(resp['total']) {
      var pct = parseInt(100*(resp['current']/resp['total']));
      document.getElementById('pbar').style.width = ''+pct+'%';
      document.getElementById('ppct').innerHTML = " "+pct+"%";
      document.getElementById('ptxt').innerHTML = resp['current']+" of "+resp['total']+" bytes";
    }
    setTimeout("update_progress()",500);
  } else if(resp['cancel_upload']) {
    txt="Cancelled after "+resp['current']+" bytes!"; 
    document.getElementById('ptxt').innerHTML = txt;
    setTimeout("progress_win.hide(); window.location.reload(true);",2000);
  }
}
var progress_callback = { success:fP }
 
function update_progress() {
  progress_key = document.getElementById('progress_key').value;
  YAHOO.util.Connect.asyncRequest('GET','progress.php?progress_key='+progress_key, progress_callback);
}
 
var progress_win;
 
function postForm(target,formName) {
  YAHOO.util.Connect.setForm(formName,true);
  YAHOO.util.Connect.asyncRequest('POST',target,callback);
/* Is there some event that triggers on an aborted file upload? */
/*   YAHOO.util.Event.addListener(window, "abort", function () { alert('abort') } ); */
  progress_win = new YAHOO.widget.Panel("progress_win", { width:"420px", fixedcenter:false, underlay:"shadow", close:false, draggable:true, modal:true, effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.3} } );
  progress_win.setHeader("Uploading "+document.getElementById('test_file').value+" ...");
  progress_win.setBody('<div style="height: 1em; width: 400px; border:1px solid #000;"> <div id="pbar" style="background: #99e; height: 98%; width:0%; float:left;">&nbsp;</div> <div id="ppct" style="height: 90%; position: absolute; margin: 1 0 0 185;">0%</div></div><div id="ptxt" style="margin: 3 0 0 5">0 of 0 bytes</div>');
  progress_win.render(document.body);
  update_progress();
}
</script>
</head>
<body>
 <form enctype="multipart/form-data" id="upload_form" action="" onsubmit="postForm('progress.php','upload_form'); return false;" method="POST">
  <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo uniqid()?>"/>
  <input type="file" id="test_file" name="test_file"/><br/>
  <input type="submit" value="Upload!"/>
 </form>
 <div id="progress_win"> 
    <div class="hd" style="color: #222; background: #bbb"></div> 
    <div class="bd"></div> 
    <div class="ft"></div> 
 </div> 
</body>
</html>