用php寫circular queue

edited 三月 5 in PHP新手區
大家好
想請問大家我寫的程式哪裡有問題
現在卡在我加東西進去queue,刪除後,但主程式還是判斷說裡面有東西。
麻煩大家幫我看一下
謝謝
//circular_queue.php
<?php

session_start();

$user_name = $_SESSION['user_name'];
$name1 = $_SESSION['name'];
$MAX_QUEUE = 5000; 
$STR_LEN = 500;
$queue[$MAX_QUEUE][$STR_LEN];
$front=1;
$rear=1;


function isFull(){
	global $rear, $MAX_QUEUE, $front;
	return $rear % $MAX_QUEUE = $front;
}

function isEmpty(){
	global $front, $rear;
	return $rear == $front;
}

function Add($item){
    global $queue, $front, $rear, $MAX_QUEUE;
 
 	if (isFull()){
  		echo("Circular Queue is full!"."<br>");
 	}
 	else{
 		echo("Circular Queue add:".$item."<br>");
 		$rear = ($rear + 1) % $MAX_QUEUE;
 		$queue[$rear] = $item;
    }
}

function Delete(){
	global $item, $queue, $front, $rear, $MAX_QUEUE;

 	if (isEmpty()){
  		echo("Circular Queue is empty!"."<br>");
 	}
 	else{
 		$front = ($front+1) % $MAX_QUEUE; 
 		$item = $queue[$front];
 		echo($item." is deleted."."<BR>");
 	}
}


Add($user_name);
Add($name1);
echo '<meta http-equiv=REFRESH CONTENT=1;url=mainloop.php>';

?>
//mainloop.php
<?php
include 'circular_queue.php';

while(1){
	if(isEmpty()){
		echo "Circular queue is empty!"."<BR>";
		sleep(5);
		echo"等待中";
		return;
	}
	else{
		Delete();
		Delete();
		echo '<meta http-equiv=REFRESH CONTENT=1;url=mt1.php>';
		return;
	}
}
?>
//mt1.php
<?php
session_start();
$name1=$_SESSION['name'];
$name = "Project ".$_SESSION['name'];
$user_name =$_SESSION['user_name'];
$filename2 = $_SESSION['filename'];
$filename2_v = explode(".", $filename2)[0] .".v";

$file_name = $name1."_mt".".bat"; //檔案名稱
  $open = @fopen(";mt/$file_name","w+"); //開啟檔案,要是沒有檔案將建立一份

  @fwrite($open,"cd C:\AppServ\www\mt"."\r\n"."mt.exe  ".$filename2."\r\n"."pause"); 
  fclose($open);
  if(file_exists("mt")){
         //copy($file,"cloudstasim/$user_name/accounting/".$file);
      }else{
         mkdir(mt,0777);
         //copy($file,"cloudstasim/$user_name/accounting/".$file); 
     }

exec("cmd /c C:\AppServ\www\mt/".$file_name);


echo"執行成功";


  if(file_exists("result")){
         //copy($file,"cloudstasim/$user_name/accounting/".$file);
      }else{
         mkdir(result,0777);
         //copy($file,"cloudstasim/$user_name/accounting/".$file); 
     }

copy("C:\AppServ\www\mt/".$filename2_v, "cloudstasim/$user_name/$name/result/".$filename2_v);



  mysql_connect('localhost','root','3141121');
  mysql_select_db('count');
  mysql_set_charset('utf8');


  session_start();
  $user_name =$_SESSION['user_name'];
  $name = "Project ".$_POST['name'];
  $file_name = "mt_count.txt";
  $file = @file(";cloudstasim/$user_name/accounting/$file_name");
  $open = @fopen(";cloudstasim/$user_name/accounting/$file_name","w+");

  @fwrite($open,$file[0]+1);
  fclose($open);
  echo "<BR/>執行次數:";
  echo @$file[0]+1;


$mt_count=$_POST['mt_count'];

$txtFile = fopen("C:/AppServ/www/cloudstasim/$user_name/accounting/mt_count.txt","r");
if ($txtFile)
{
  while (!feof($txtFile))
  {           
      $mt_count = fgets($txtFile);
      //echo $info;
      //echo "<br />";
  }

  fclose($txtFile);

  if(!($database = mysql_connect("localhost","root","3141121"))){
  die("Can not connect database! <br />");
  }

  if(!mysql_select_db("count",$database)){
  die("Can not open course database! <br />");
  }
  // $info=$_POST['info'];

  $txtFile = fopen("C:/AppServ/www/cloudstasim/$user_name/accounting/mt_count.txt","r");
  if ($txtFile){
  while (!feof($txtFile))
        {          
  $mt_count = fgets($txtFile);
  $str="INSERT INTO mt (mt_count) values ('$mt_count')";
  $res=mysql_query($str);
        }
  fclose($txtFile);
  }else{
  echo "error";
  }
}
    if(file_exists("cloudstasim/$user_name/accounting")){
         //copy($file,"cloudstasim/$user_name/accounting/".$file);
      }else{
         mkdir(cloudstasim."/".$user_name."/".accounting,0777);
         //copy($file,"cloudstasim/$user_name/accounting/".$file); 
     }

?>

<?php

echo '<meta http-equiv=REFRESH CONTENT=1;url=mainloop.php>';
?>



<form action="mt.php" method="post">
<input type="submit" value="回到執行頁">
</form>


<form action="mt_upload.php" method="post">
<input type="submit" value="上傳.V檔進資料庫">
</form>
標籤:
Sign In or Register to comment.