


php processes database data and returns a method to the client to display the current status for each piece of data processed. , the current status of the database
php processes a large amount of data, and each time a piece of data is processed, it returns a method to the client to display the current status.
Similar to dedecms to generate static pages
Ideas:
Experimental process:
1. Create database and tables
<span>create</span><span> databases handle; </span><span>create</span> <span>table</span> <span>user</span><span>( id </span><span>int</span> unsigned <span>not</span> <span>null</span> auto_increment <span>primary</span> <span>key</span><span>, name </span><span>varchar</span>(<span>8</span><span>), sex </span><span>tinyint</span>(<span>1</span>) <span>default</span> <span>'</span><span>1</span><span>'</span><span>, score </span><span>int</span> <span>not</span> <span>null</span><span>, state </span><span>tinyint</span>(<span>1</span><span>) );</span>
2. Add data to the table (not examples)
3. Create index.html client, a.php server 1, b.php server 2
Index.html:
<span><!</span><span>DOCTYPE html</span><span>></span> <span><</span><span>html </span><span>lang</span><span>="en"</span><span>></span> <span><</span><span>head</span><span>></span> <span><</span><span>meta </span><span>charset</span><span>="UTF-8"</span><span>></span> <span><</span><span>title</span><span>></span>客户端<span></</span><span>title</span><span>></span> <span></</span><span>head</span><span>></span> <span><</span><span>body</span><span>></span> <span><</span><span>button </span><span>onclick</span><span>="send('a.php?state=0')"</span><span>></span>开始请求<span></</span><span>button</span><span>></span> <span><</span><span>div </span><span>style</span><span>="position: fixed;width: 500px;height: 300px;top: 100px;background: gray"</span><span>></span> <span><</span><span>span </span><span>style</span><span>="color: white;font-size: 20px;"</span><span>></</span><span>span</span><span>></span> <span></</span><span>div</span><span>></span> <span><</span><span>script </span><span>type</span><span>="text/javascript"</span><span> src</span><span>="./jquery-1.10.2.min.js"</span><span>></</span><span>script</span><span>></span> <span><</span><span>script </span><span>type</span><span>="text/javascript"</span><span>></span> <span>//</span><span>创建一个模态框</span> <span>function</span><span> display(value){ $(</span><span>'</span><span>span</span><span>'</span><span>).html(value); } </span><span>//</span><span>ajax</span> <span>function</span><span> send(dizhi){ $.ajax({ type: </span><span>"</span><span>get</span><span>"</span><span>, url: dizhi, success: </span><span>function</span><span>(msg){ </span><span>var</span><span> arr</span><span>=</span><span>JSON.parse(msg); console.log(arr); </span><span>//</span><span>alert(arr.value);</span> <span>var</span><span> tishi</span><span>=</span><span>"</span><span>已经处理 </span><span>"</span><span>+</span><span>arr.now </span><span>+</span><span>"</span><span>个,共</span><span>"</span><span>+</span><span>arr.all</span><span>+</span><span>"</span><span>个</span><span>"</span><span>; display(tishi); </span><span>if</span><span>(arr.now</span><span>!=</span><span>arr.all){ send(</span><span>"</span><span>a.php?now=</span><span>"</span><span>+</span><span>arr.now</span><span>+</span><span>"</span><span>&all=</span><span>"</span><span>+</span><span>arr.all); }</span><span>else</span><span>{ alert(</span><span>"</span><span>完成!</span><span>"</span><span>); } } }); } </span><span></</span><span>script</span><span>></span> <span></</span><span>body</span><span>></span> <span></</span><span>html</span><span>></span>
a.php:
<?<span>php </span><span>require</span>('./dbconfig.php'<span>); </span><span>$link</span>=<span>mysql_connect</span>(HOST,USER,PASS) or <span>die</span>('数据库链接失败'<span>); </span><span>mysql_select_db</span><span>(DBNAME); </span><span>/*</span><span> 查询数据 $sql="select * from user"; $result=mysql_query($sql); $row=mysql_fetch_assoc($result); var_dump($row); </span><span>*/</span> <span>/*</span><span> 循环插入 for($i=3;$i<=100;$i++){ $sql= "insert into user(name,score,state) values('z".$i."',".$i.",1)"; mysql_query($sql); } </span><span>*/</span> <span>/*</span><span>查询需要处理的数据总数</span><span>*/</span> <span>//</span><span>isset($_GET['state'])?$_GET['state']:0;</span> <span>if</span>(<span>isset</span>(<span>$_GET</span>['state'<span>])){ </span><span>$sql</span>="select count(*) from user"<span>; </span><span>$result</span>=<span>mysql_query</span>(<span>$sql</span><span>); </span><span>$all</span>=<span>mysql_result</span>(<span>$result</span>,0<span>); </span><span>$now</span>=0<span>; </span><span>header</span>("Location: b.php?all={<span>$all</span>}&now=0"<span>); }</span><span>else</span><span>{ </span><span>header</span>("Location: b.php?all={<span>$_GET</span>['all']}&now={<span>$_GET</span>['now']}"<span>); } </span><span>/*</span><span>返回当前处理的数据</span><span>*/</span>
b.php:
<?<span>php </span><span>require</span>('./dbconfig.php'<span>); </span><span>$link</span>=<span>mysql_connect</span>(HOST,USER,PASS) or <span>die</span>('数据库链接失败'<span>); </span><span>mysql_select_db</span><span>(DBNAME); </span><span>/*</span><span>返回当前处理的数据</span><span>*/</span> <span>//</span><span>$id=$_GET['id'];//获取将要处理的id</span> <span>$now</span>=<span>$_GET</span>['now'];<span>//</span><span>已经处理的个数</span> <span>$all</span>=<span>$_GET</span>['all'];<span>//</span><span>总共要处理的个数</span> <span>$sql</span>="select score from user limit {<span>$now</span>},1"<span>; </span><span>$result</span>=<span>mysql_query</span>(<span>$sql</span><span>); </span><span>$value</span>=<span>mysql_result</span>(<span>$result</span>, 0<span>); </span><span>$now</span>++<span>; </span><span>$arr</span>=<span>array</span><span>( </span>'now'=><span>$now</span>, 'all'=><span>$all</span>, 'value'=><span>$value</span><span> ); </span><span>//</span><span>print_r($arr);</span> <span>echo</span> json_encode(<span>$arr</span>);
dbconfig.php:
<?php define('HOST','127.0.0.1'); define('USER', 'root'); define('PASS','root'); define('DBNAME','handle');
That’s all~

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


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

WebStorm Mac version
Useful JavaScript development tools

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.
