Table of Contents
回复讨论(解决方案)
拍拍平台-价格及库存管理系统
Home Backend Development PHP Tutorial PHP循环中进度显示以及"假死"

PHP循环中进度显示以及"假死"

Jun 23, 2016 pm 02:25 PM

理论上程序应该运行完500次然后才显示成功,但是基本只能运行个十来次页面就开始全白(同时网页中载入的标志也消失了),就不再往下继续执行程序了
求助这种问题应该如何解决,谢谢

另外,进度方面不知道应该如何处理。再次感谢


<?PHPfor ($i=1;$i<500;$i++){	file_put_contents("{i}.txt",$i);	sleep(3);	$s = $i/100;	if($s==ceil($s)) {		$s = $i/500;		echo "进度:{$s}<BR>";		}}echo "OK";?>
Copy after login


回复讨论(解决方案)

3秒×500= 多长时间?

不死才怪

3秒×500= 多长时间?
没有设置运行时间,不死才怪

nnd,csdn给我500还让我多发了一次……

跟运行时候太长有关系,你还第次休息了3秒

本来是一个采集再写入数据库的程序,这里只是想表达大概的意思 代码少 易看

set_time_limit吧

以下是我原程序的主要内容

<?php 	require_once("config.php");	session_start();		if($_SESSION['admin']!="ok"){		header("Location: login.php");		exit;	}    $_GET['act']?$act=$_GET['act']:$act="view";    if(!in_array($act,array("save","scan","view"))){        $act="view";    }	/*		保存后台设置	*/		if($act=="save"){		$data=array(            "appOAuthkey"=>$_POST["appOAuthkey"],            "user"=>$_POST["user"],            "pw"=>$_POST["pw"],            "appOAuthID"=>$_POST["appOAuthID"],            "accessToken"=>$_POST["accessToken"],            "appOAuthkey"=>$_POST["appOAuthkey"],            "lirun"=>$_POST["lirun"],            "uin"=>$_POST["uin"]        );        $db->row_update("config",$data,"id=1");        if($db->get_errno()){            alert_back("设置失败!");        }else{            alert_back("设置成功!");        }	}    $conf=$db->row_query_one("select * from config where id=1");    $data=$db->row_query("select * from data");	if($act=="scan"){		//$db->row_delete("data","");		$itemState = $_POST['itemState'];//商品状态		$PageSize = GetPageSize($itemState);//商品页数		for ($i=1; $i<=$PageSize; $i++) {			$htm = GetItemList($itemState,$i);			$xml = simplexml_load_string($htm);			$item = $xml->itemList->item;			$itemName = $item->itemName;			$itemName = iconv('utf-8', 'gb2312', $itemName);			$itemState = $item->itemState;			$itemCode = $item->itemCode;			$itemPrice = $item->itemPrice;			$db->row_insert("data",array("ProName"=>$itemName,"item"=>$itemCode,"Price"=>$itemPrice,"itemState"=>$itemState,"add_time"=>$time));			//进度信息 PageSize					}		alert_back("扫描结束,共计信息数:{$PageSize}!");	}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>价格及库存管理系统</title><link rel="shortcut icon" href="favicon.ico" /><link href="all.css" rel="stylesheet" type="text/css" /></head><body><div style="float:right;padding:10px;"><a href="login.php?act=logout">注销登录</a></div>	<h1 id="拍拍平台-价格及库存管理系统">拍拍平台-价格及库存管理系统</h1>	<form action="?act=save" method="post">	<table border="0" style="width:98%;" cellpadding="0" cellspacing="0" >	<tr class="tit"><td colspan="2">系统设置</td></tr><tr><td>用户名:</td><td> <input class="input" type="text" name="user" value="<?php echo $conf['user'];?>"></td></tr><tr><td>用户密码:</td><td> <input class="input" type="password" name="pw" value="<?php echo $conf['pw'];?>"></td></tr><tr><td>uin:</td><td> <input class="input" type="text" name="uin" value="<?php echo $conf['uin'];?>"></td></tr><tr><td>appOAuthID:</td><td> <input class="input" type="text" name="appOAuthID" value="<?php echo $conf['appOAuthID'];?>"></td></tr><tr><td>appOAuthkey:</td><td> <input class="input" type="text" name="appOAuthkey" value="<?php echo $conf['appOAuthkey'];?>"></td></tr><tr><td>accessToken:</td><td> <input class="input" type="text" name="accessToken" value="<?php echo $conf['accessToken'];?>"></td></tr><tr><td>利润:</td><td> <input class="input" type="text" name="lirun" value="<?php echo $conf['lirun'];?>"> 单位:分</td></tr><tr><td></td><td><button type="submit">设置</button><button type="reset">重置</button></td></tr></table></form><br/><br />		<table border="0" style="width:98%;" cellpadding="0" cellspacing="0" >	<tr class="tit"><td colspan="3">商品管理</td></tr>	<form action="?act=scan" method="post">	<tr>		<td style="width: 15%;">商品采集更新:</td>		<td>					<select name="itemState" style="width:210px;">			<?php   			 foreach($itemStates as $k=>$v){        		echo '<option value="'.$k.'">'.$v.'</option>';    			} 			?>			</select>		</td>		<td>			<button type="submit">采集更新数据</button>  		</td>  	</tr>	</form></table><br /><br />	<table border="0" style="width:98%;" cellpadding="0" cellspacing="0" >	<tr class="tit"><td>商品信息管理(共有<?php echo count($data);?>条信息)</td></tr><tr><td>    <table style="width: 98%;"><tr class="tit1"><td>ID</td><td>商品名称</td><td>Item</td><td>价格</td><td>状态</td><td>添加时间</td><td>更新时间</td><td>操作</td></tr><?php    	$ii=0;foreach($data as $key=>$val){        echo '<tr><td>'.$val['id'].'</td><td>'.$val['ProName']."</td><td><a href=http://auction1.paipai.com/".$val['item']." target=_blank>".$val['item'].'</a></td><td>'.$val['Price'].'</td><td>'.$status_str[$val['itemState']].'</td><td>'.date("Y-m-d H:i:s",$val['add_time']).'</td><td>'.date("Y-m-d H:i:s",$val['up_time']).'</td><td><a href="?act=del&id='.$val['id'].'">删除</a></td></tr>';		$ii ++;		//if ($ii>2) break;}?>    </table></td></tr></table><script type="text/javascript">setTimeout("del_ifr()",5000);function del_ifr(){document.getElementById("ifr").innerHTML='';}</script></body></html>
Copy after login

set_time_limit吧

加入了这个 程序能顺利运行结束(时间比较长点)

但是这个进度显示好像得运行结束了才一起显示出来。。。

php是一次计算一次输出,即使像CLI那样边计算边输出,也要不断刷屏才能实现进度条效果
进度在客户端显示,你觉得php会在服务器端计算->客户端显示->服务器端计算->客户端显示->……这样么?

如果你想要这样效果,你就要把循环拆开,客户端收到第一个数据,然后ajax向服务器发出next请求,php再计算下一个,向客户端发结果,客户端再ajax……

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1246
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

See all articles