理论上程序应该运行完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";?>
回复讨论(解决方案)
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>
set_time_limit吧
加入了这个 程序能顺利运行结束(时间比较长点)
但是这个进度显示好像得运行结束了才一起显示出来。。。
php是一次计算一次输出,即使像CLI那样边计算边输出,也要不断刷屏才能实现进度条效果
进度在客户端显示,你觉得php会在服务器端计算->客户端显示->服务器端计算->客户端显示->……这样么?
如果你想要这样效果,你就要把循环拆开,客户端收到第一个数据,然后ajax向服务器发出next请求,php再计算下一个,向客户端发结果,客户端再ajax……

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!
