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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? Apr 01, 2025 pm 03:09 PM

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...

See all articles