0115 | Multipart Page Generator
เทคนิคนี้เอามาจาก facebook ฮะ :) แหล่มดี คิดได้ไง นับถือมาก
จริงๆ ของ fb เขียนดีกว่านี้เยอะ นี่ implement แบบลวกๆ สุดยอด
อันนี้หน้า index.php
<!DOCTYPE html>
<html>
<head>
<title>Multipart Page Generator Framework</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style type="text/css">
body{margin:0;padding:0;font:10pt Tahoma;}
div{margin:5px;padding:5px;border:1px dotted #aaf;}
div.c{text-align:center;}
#wrapper{width:990px;margin:0 auto;border:0;padding:0;}
</style>
<script type="text/javascript">
function mppg_returncontent(id, content) {
document.getElementById(id).innerHTML = content;
}
</script>
</head>
<body>
<div id="wrapper">
<div id="command"></div>
<div id="status"></div>
</div>
<?php
flush();
$urls = array('http://localhost/command.php', 'http://localhost/status.php');
$curl_arr = array();
$master = curl_multi_init();
foreach($urls as $id => $url) {
$curl_arr[$id] = curl_init($url);
curl_multi_add_handle($master, $curl_arr[$id]);
}
$running = 0;
$lastrun = 0;
do{
curl_multi_exec($master,$running);
//$info = curl_multi_info_read($master);
flush();
usleep(5000);
} while ($running > 0);
//close the handles
foreach($urls as $id => $url) {
curl_multi_remove_handle($master, $curl_arr[$id]);
}
curl_multi_close($master);
?>
</body>
</html> |
ส่วนอันนี้ prepend แปะหน้าย่อยข้างใน
<?php $partid = 'command'; function mppg_returncontent($buffer) { global $partid; return '<script type="text/javascript"> mppg_returncontent("'.$partid.'", "'.addslashes(str_replace(array("\n","\r"), '', $buffer)).'"); </script>'; } ob_start('mppg_returncontent'); ?>content here |

[…] This post was mentioned on Twitter by icez network, เพชรบูรณ์ดอทคอม. เพชรบูรณ์ดอทคอม said: 0115 | Multipart Page Generator http://bit.ly/eCgRNc […]