ãã£ãšãã®èšäºã®ã¿ã€ãã«ãèªãã§ãã人ãã«ãã«ãç¬ã£ãŠããã ãã·ã¥ãŒã¯åé¯ã«ã€ããŠå€ããç¥ã£ãŠããïŒããšæãã§ãããã ãã®èšèªãŸãã¯ãã®èšèªã®ã¯ãŒã«ãã«ã€ããŠã®è°è«ã¯æ±ºããŠåãŸãããšã¯ãããŸããããã¹ã¿ãã¯å šäœãæ ¹æ¬çã«å€æŽããåã«ãã¹ãŠã®å¯èœæ§ãçµãåºãã®ã奜ããªã®ã§ãç§ã«ãšã£ãŠã¯ãèšèªãå€æŽããããã®ããã»ã©å€ãã®æ¡ä»¶ãå人çã«ã¯èŠãŠããªããããããŸããã æè¿ãTornadoã§ãã£ãããäœæããããšã«é¢ããåºçç©ããããPHPã䜿çšããŠåæ§ã®åé¡ãã©ã®ããã«è§£æ±ºãããã«ã€ããŠè©±ããããšæããŸããã
èæ¯
ããæŽããæ¥ãç§ã¯WebSocketã«ã€ããŠç¥ãããšã«ããŸããã ãã®æè¡ã«èå³ããããããŸããããæšæ¥ã ãç»å Žãããšã¯èšããŸããã§ããããããã¯å€ãã®æ¬ é¥ã«æ©ãŸãããŠãã瀟äŒåŠé¢é£ã®ãã£ãããµãŒãã¹ã®éå§ãšäžèŽããŸããã ããã¯ç§ã«ç«¶äºã®ã¬ãŒã¹ã«åå ããè奮ãäžããŸããã Webãœã±ããã®äœ¿çšã¯ããŸã£ããæ°ããææãªãœãªã¥ãŒã·ã§ã³ã®ããã«æããŸããã
æ¥ç¶ã¯äžå®ã§åæ¹åã«ç¢ºç«ãããã¯ã©ã€ã¢ã³ãåŽã§ã¯ãäœæ¥ã¯4ã€ã®ã€ãã³ãïŒ onopen ã onclose ã onerrorããããŠãã¡ããonmessageïŒã®åŠçã«åæžãããŸãã setIntervalãéå°ãªãã©ãã£ãã¯ããµãŒããŒè² è·ã«ãããªã¯ãšã¹ãã¯ãããããŸããã
ããã§ããããäœã§ããããç解ããŠããªã人ã®ããã«ãå°ãäœè«ããŸãã
2000幎代åé ã®runetã«ç²ŸéããŠãã人ã¯ããã¹ãŠãé ããªããããã¡ãªãåäœããããŸããŸãªãã£ãããµãŒãã¹ãèŠããŠãããããããŸããã
AJAXã¯å°ãé ããŠç»å Žããã¯ããã«è¯ããªããŸããããæ¬è³ªçã«ã¯ååã¯å€ãã£ãŠããŸããã éä¿¡ãããããŒã¿éãå°ãªãããã«iframeã®äœ¿çšãæåŠãããµãŒããŒã®è² è·ãå°ãæžããããšãã§ããªãå Žåãé€ããã¯ã©ã€ã¢ã³ãéšåã¯ã¿ã€ããŒã«åŸã£ãŠäžå®ã®é »åºŠã§ãµãŒããŒãããŒãªã³ã°ããŸããã
å®éãèšåããããã£ãããµãŒãã¹ã¯å€å žçãªAjaxãã£ããã§ããã
éžæããã¢ãããŒãã«ã¯ãçå®ãšã³ã€ã³ã®è£åŽããããŸãã
- å€ããã©ãŠã¶ã§ã®ãµããŒãã®æ¬ åŠ
- æåæ¥ç¶å¶åŸ¡
- ãµãŒããŒããŒã¢ã³ã®äœ¿çš
æåã®åé¡ã«ã€ããŠæ¬åœã«å¿é ããŠããªãã£ãå Žåã察象èªè ã¯ãWebSocketã®ãµããŒããé·ãéå®è£ ãããŠããçŸä»£ã®ã³ã³ãã¥ãŒã¿ãŒãšã¢ãã€ã«ã¬ãžã§ãããåããè¥è ã§ãããã2çªç®ã®åé¡ã«ã€ããŠã¯ããã«å°é£ããããŸãããããã«ã€ããŠã¯åŸã§èª¬æããŸãã
ããŒã¢ã³ã®äœ¿çšã«ã¯å€ãã®æ©èœããããŸãã
- ããŒã¢ã³ãåèµ·åããããšã«ãã£ãŠã®ã¿ã³ãŒããæŽæ°ã§ããŸã-ãããã£ãŠãchatllanã®å Žåãããã¯ããçšåºŠçºçããŸã
- èŽåœçãªãšã©ãŒãšæªåŠçã®äŸå€ã«ãããããŒã¢ã³ãã¯ã©ãã·ã¥ããŸã-ã³ãŒãã¯ãé²åŒŸãã§èšè¿°ããå¿ èŠããããŸã
- ããŒã¢ã³ã¯å°çšã®ç©ºãããŒãã䜿çšããå¿ èŠããããŸã-ããã¯ãå³ãããã¡ã€ã¢ãŠã©ãŒã«ã®åŸãã«åº§ã£ãŠãã人ã«ãšã£ãŠåé¡ã§ã
- ãã³ããããã³ã°æ©èœã䜿çšãã
ãåžžé§ããã°ã©ã ããäœã§ãããèããããšããªã人ã§ããrun-run-run-dieãã®åçã§åäœããWebããŒãžã®ã³ãŒããæžããã ãã®äººã¯ãããŒã¢ã³ãåããŠæžããšãã«ãã¿ãŒã³ãã¬ãŒã¯ãçµéšããŸãã ããšãã°ãã€ã³ã¹ã¿ã³ã¹åããããªããžã§ã¯ãã¯ãããŒã¿ããŒã¹ã¿ã€ãã®ã¹ãã¬ãŒãžã䜿çšããã«é·æéãçåãããæ å ±ãä¿åã§ããããŒã¢ã³ãžã®ããŸããŸãªæ¥ç¶ããã¢ã¯ã»ã¹ã§ããããšãããããŸãã ããããã圌ã®å·çäžã«ãé¢æ°ããããã¯ããåé¡ãšãéåæã®ããã®PHPã·ã£ãŒããã³ã°ã®æ¬ åŠã«æãæ·±å»ã«ééããå¯èœæ§ããããŸãã
äžè¬ã«éåæãšã¯äœã§ããïŒ ç°¡åãªæ¹æ³ã§ããã°ãããã¯ã
UPDïŒ alekciyã¯æ£ããè¿°ã¹ãŸããïŒ
æ··ä¹±ããå¿ èŠã¯ãããŸããã éåæïŒ=䞊åã ã¯ã©ã·ãã¯JSã¯éåæã«å®è¡ã§ããŸããã䞊åã«ã¯å®è¡ã§ããŸããïŒã·ã³ã°ã«ã¹ã¬ããVMã䜿çšïŒã æçšãªèªã¿ç©ïŒ JavaScriptã§ã®ã¿ã€ããŒã®åäœ ã
éåæ-äžè²«æ§ã®ãªãã³ãŒãå®è¡ã®å¯èœæ§ã 䞊è¡æ§-åãã³ãŒããåæã«å®è¡ããæ©èœã
èªè ãå°ãªããšãJavaScriptã®åºæ¬ã«ç²ŸéããŠããããšãé¡ã£ãŠããŸãã ã»ãšãã©ã®å Žåãå°ãªããšã次ã®ããã«æžããŸããïŒ
var myDomElement.onclick = function() { alert("I'm hit!"); }
å°åŠæ ¡ã§ããïŒ ããŒãžã®äžéšã®èŠçŽ ãã¯ãªãã¯ããããã®ã€ãã³ããã³ãã©ãŒã決å®ãããŸãã ããããPHPã§äŒŒããããªããšãããããšãããã©ãã§ããããã
æåã®è³ªåã¯ãããªããžã§ã¯ãã®ã€ãã³ããç¹å®ããå Žæãã§çºçããŸãã 2ã€ç®ã¯ããç¹å®ã®ã€ãã³ãã«å¯ŸããŠãªããžã§ã¯ããåžžã«ããŒãªã³ã°ãããããã«ããæ¹æ³ãã§ãã ããŠããã®ã€ãã³ããããŒãªã³ã°ãããç¹å®ã®ç¡éã®ãµã€ã¯ã«ãäœããšããŸãããã ãããŠãå€ãã®æ·±å»ãªå¶éã«çŽé¢ããŸãã 第äžã«ãããŒãªã³ã°ã®é »åºŠã¯ãã·ã¹ãã ã®å¿çãæºè¶³ã§ããããã«äœããªããããªãããã«ããå¿ èŠããããŸãã ãŸããã·ã¹ãã ã®è² è·ã«åé¡ãçããªãããã«ãé«ãããŠã¯ãããŸããã 第äºã«ãããã€ãã®ã€ãã³ããããå Žåãæåã®ãã³ãã©ãŒãåäœãããŸã§ãããäžæ¹ã®ãã³ãã©ãŒã¯åäœãéå§ããªããšããåé¡ããããŸãã ãŸããæ°åã®æ¥ç¶ãåæã«åŠçããå¿ èŠãããå Žåã¯ã©ãã§ããããïŒ
ãããã ReactPHPã¯çŸå Žã«ç»å Žããéæ³ããããŸãã
æå
- ãµãŒããŒåŽã¯ã Ratchetããã±ãŒãžã«åºã¥ããŠããŸãããããã¯ãåºæ¬çã«WebSocketãæäœããããã®ReactPHPã®ã¢ããªã³ã§ãã
- AngularJSã®ãããªjavascriptãã¬ãŒã ã¯ãŒã¯ã䜿çšãããšããã¢ã€ãã¢ããããŸãããããã®æç¹ã§ç§ã¯ã§ããã ãæ©ããããžã§ã¯ããéå§ãããã£ãã®ã§ãæ°ãããã¬ãŒã ã¯ãŒã¯ã®åŠç¿ã¯å³ããã¹ã±ãžã¥ãŒã«ã«åãŸããŸããã§ããã ãã®ãããæåã¯è£žã®javascriptããããããã§ãjQueryãæ¥ç¶ãããŠããŸããã
- ã¬ã€ã¢ãŠããšãã¶ã€ã³ãé¢åããããªãã£ãã®ã§ãTwitter Bootstrap 3ã䜿ããŸãã
- ããŒãžã®ã¿ã€ãã«ãç¹æ» ãããããéç¥é³ã鳎ãããããã代ããã«ãHTML5éç¥ã䜿çšããããšã¯ååã«éèŠã ãšèããŸããã
- çæãããããŒã¢ã³ã«ã¯ç¬èªã®ããŒããå¿ èŠã ã£ãããããã¡ã€ã¢ãŠã©ãŒã«ã®åé¡ã解決ããããã«ãnginxã䜿çšããŠWebSocketãããã·ãèšå®ããŸããã èå³ã®ããã«ãSSL蚌ææžããã蟌ã¿ãŸãã
ç°¡åãªæ§é
ãµãŒããŒããŒãã¯ã2ã€ã®é察称ã³ãŒãããŒãã§æ§æãããŠããŸãããã£ãã·ãã¯WebããŒãžïŒã€ã³ããã¯ã¹ããã¹ã¯ãŒãå埩ïŒãšãã¢ãã£ãããµãŒãã¹ã§ãã
ã¡ã€ã³ããŒãžã¯ãã¯ã©ã€ã¢ã³ãWebã¢ããªã±ãŒã·ã§ã³ã®ããŒããšã»ãã·ã§ã³ã®åæåã®ã¿ã¹ã¯ã解決ããŸãã
ããŒã¢ã³ã¯åºæ¬çã«ãMyApp \ Chatã¯ã©ã¹ã®åœ¢åŒã®Ratchetããã±ãŒãžã®MessageComponentInterfaceã€ã³ã¿ãŒãã§ãŒã¹ã®å®è£ ã§ãã å®è£ ãããã¡ãœããã¯ã onOpen ã onClose ã onErrorãããã³onMessageã€ãã³ããåŠçããŸã ã
onErrorãé€ãåãã³ãã©ãŒã¯ã責任ã®é£éãã¿ãŒã³ã§ãã æãèšå€§ãªã³ãŒãã¯onMessageã§ãã³ã³ãããŒã©ãŒã«å解ãããŸããã
åé¡ãšè§£æ±ºç
- æåã«çŽé¢ããªããã°ãªããªãã£ãã®ã¯ãèŽåœçãšã©ãŒãã«ã¹ã¿ã ãã³ãã©ãŒã®ãªããšã©ãŒãæªåŠçã®äŸå€ãããŒã¢ã³ã殺ãããšã§ããã èŽåœçããã³äŸå€ãããå Žåãåé¡ã¯ãã¹ãã®å©ããåããŠã®ã¿è§£æ±ºãããŸãã ç§ã®æ®å¿µãªããšã«ãæã¯æéã®æ·±å»ãªäžè¶³ã®ããã«ãã¹ãã«å°éããŸããã§ããããããã§ãããã§ãã ãããããåç¥ã®ãããªåçŽãªãšã©ãŒã¯ãã«ã¹ã¿ã ErrorHandler +ãã®ã³ã°ã䜿çšããã ãã§è§£æ±ºãããŸãã
- åé¡ã¯ãæ°æ¥éã®æäœã®åŸã誰ããåæãããã£ããããŒã¢ã³ãCPUã®100ïŒ
ã䜿ãå§ãããšãã«æããã«ãªããŸãããããã£ããæäœã«ãã¬ãŒãã¯ãããŸããã§ããã GitHubã«ããèè
Ratchetã®ããããä¿®æ£ããŸããã ãã ããäœããã®çç±ã§ãReactPHPããã±ãŒãžã«ã¯ãŸã å«ãŸããŠããŸããã
ãããdiff --git a / vendor / react / stream / React / Stream / Buffer.php b / vendor / react / stream / React / Stream / Buffer.php
ã€ã³ããã¯ã¹e516628..4560ad9 100644
@@ -83.8 +83.8 @@ class Buffer extends EventEmitter implements WritableStreamInterface
ãããªãã¯é¢æ°handleWriteïŒïŒ
{
-ifïŒïŒIs_resourceïŒ$ this-> streamïŒ||ïŒ 'generic_socket' === $ this-> meta ['stream_type'] && feofïŒ$ this-> streamïŒïŒïŒ{
-$ this-> emitïŒ 'error'ãarrayïŒnew \ RuntimeExceptionïŒ 'Closed to invalid or invalid streamã'ïŒïŒïŒ;
+ ifïŒïŒis_resourceïŒ$ this-> streamïŒïŒ{
+ $ this-> emitïŒ 'error'ãarrayïŒnew \ RuntimeExceptionïŒ 'Tried to write to invalid streamã'ïŒã$ thisïŒïŒ;
åž°ã
}
@@ -107.6 +107.12 @@ class Bufferã¯EventEmitterãWritableStreamInterfaceãå®è£ ããããšãæ¡åŒµããŸã
åž°ã
}
+ ifïŒ0 === $ sent && feofïŒ$ this-> streamïŒïŒ{
+ $ this-> emitïŒ 'error'ãarrayïŒnew \ RuntimeExceptionïŒ 'Tried to write to closed streamã'ïŒã$ thisïŒïŒ;
+
+ãªã¿ãŒã³;
+}
+
$ len = strlenïŒ$ this-> dataïŒ;
ifïŒ$ len> = $ this-> softLimit && $ len-$ sent <$ this-> softLimitïŒ{
$ this-> emitïŒ 'drain'ïŒ;
- æ¥ç¶ã®ä¿æã¯ããããéèŠãªåé¡ã§ãã æç·ãããã¯ãŒã¯ãŸãã¯é©åãªWi-Fiãä»ããéåžžã®æ¥ç¶ã§ã¯ããã¹ãŠãæ£åžžã§ããã ããããã¢ãã€ã«ã€ã³ã¿ãŒãããããé»è©±ãããããšãã¢ãã€ã«ãªãã¬ãŒã¿ã¯æ°žç¶çãªæ¥ç¶ã奜ãŸããããã€ãã®æ¡ä»¶ã«å¿ããŠåæããããšãæããã«ãªããŸããã ããšãã°ãBSã®è² è·ãäœãããã£ããã§å
šå¡ãæ²é»ããŠããå Žåã30ç§åŸã«ç Žæ£ãããå¯èœæ§ããããŸãã ãããŠãããã¯æšãŠãããªããããããŸããã ããã§ãäºé²ã®ããã«ãpingã³ãã³ãããµãŒããŒã«åšæçã«éä¿¡ããŠã¢ã¯ãã£ããã£ãäœæããŸããã ããããããå¿ããBSã§ããããšãå€æãããããããã¯æ©èœããŸããã§ããã
äžè¬ã«ãã¢ã«ãŽãªãºã ã®å®è£ ã¯é·ãæéãèŠæ±ããŠããŸãããã¿ã€ã ã¢ãŠãåŸã«ååšãããŠãŒã¶ãŒã®é åããã®ãŠãŒã¶ãŒã®é 延åæã æããã«ãããã«ã¯éåæã³ãŒãã®äœ¿çšãå¿ èŠã§ãã åœç¶ãããã§ã¯ç¡ç ã¯ãããŸããã§ããã ãã¥ãŒãµãŒããŒãå«ããããããçš®é¡ã®å®è£ ãªãã·ã§ã³ãèããŸããã ãœãªã¥ãŒã·ã§ã³ãèŠã€ãããã·ã³ãã«ãã€ãšã¬ã¬ã³ãã§ããããšãå€æããŸãããReactPHPã䜿çšãããšãEventLoopã«ããã£ãŠããã¿ã€ããŒã䜿çšã§ããŸãã 次ã®ããã«ãªããŸãã
private function handleDisconnection(User $user) { $loop = MightyLoop::get()->fetch(); // EventLoop, $detacher = function() use ($user) { // ... }; if ($user->isAsyncDetach()) { $timer = $loop->addTimer(30, $detacher); // 30 $user->setTimer($timer); } else { $detacher(); } $user->getConnection()->close(); }
- ããŒã¢ã³ã¢ãŒãã§ããŒã¿ããŒã¹ã«æ¥ç¶ãããšãããã©ãŒãã³ã¹äžã®çç±ããããŒã¿ããŒã¹ãéãããŸãŸã«ããæ¥ç¶ãšã©ãŒã«ãããã°ã®ç®è©°ãŸããæå°éã«æããããšãã§ããŸãã ãããã«ããŠããããŒã¿ããŒã¹ãžã®æ¥ç¶ãä¿èšŒããããã«ãåãªã¯ãšã¹ãã®åã«åŒã³åºãããæŸèæã¡ãœãããPDOã©ãããŒã«è¿œå ããå¿
èŠããããŸããã
protected function checkConnection() { try { $this->dbh->query('select 1'); } catch (\Exception $e) { $this->init(); } }
æ²ããããªãç§ã¯ãããšã¬ã¬ã³ããªè§£æ±ºçãèŠã€ããããšãã§ããŸããã§ããã ç¹ã«æ¢è£œã®predis-asyncããã±ãŒãžããããããRedisãè©Šãå¿ èŠããããŸãã - åãã©ãŠã¶ã¿ãã¯æ°ããæ¥ç¶ãçæããŸãã ãããŠãã©ãããããããç§ã¯ãŠãŒã¶ãŒãã¯ããŒã³ã«ãã£ãŠäŒæããããšãèš±å¯ããããããŸããã§ããã åãã»ãã·ã§ã³ã§ã®æ¥ç¶ãçŠæ¢ããå¿ èŠããããŸããã ãã®åäœã¯ã1ã€ã®ã»ãã·ã§ã³ã§ä»»æã®æ°ã®ãŠã£ã³ããŠãŸãã¯ã¿ãã§åæã«ç°¡åã«äœæ¥ã§ããã¯ã©ã·ãã¯ãã£ãããšã¯ç°ãªããŸãã
ãã£ããã§ã§ããããšãä»ã«åŠã¶ããš
äž»ãªæ©èœïŒ
- ãã£ããããŒã¢ã³ã¯çŽ20 MBã®ã¡ã¢ãªãæ¶è²»ãããã®æ°å€ã¯å®å®ããŠããŸãã ããã¯æªããããŸããã
- å¿ é ã®ç»é²ããªãå ŽåããŠãŒã¶ãŒã¯ããã«ãã£ããã«å ¥ããŸãã
- ç»é²ãæ¿èªãããã³ãã¹ã¯ãŒãã®å埩ã
- ãã©ã€ããŒãã»ãã·ã§ã³ãšãã©ã€ããŒãã¡ãã»ãŒãžãè¡ãããšãã§ããŸãïŒåå¥ã®ãã£ãã«ãäœæããã«ïŒã
- å人ã®ãã©ãã¯ãªã¹ãã
- 瀟äŒçã¿ã€ãã®ãã£ããã«ãŒã¬ããã
- ãŠãŒã¶ãŒã«ã¯èŠããªãããã«ãæ¥ç¶ãåæããããšåæ¥ç¶ãè¡ãããŸãã
- æ¥ç¶ã®éè€ã®é²æ¢;
- 措氎å¶åŸ¡ã
æªãç¹ïŒ
- èªäœã®ãŸãšããªORMã¯ãããŸããã
- ã»ãã·ã§ã³ãã³ãã©ãèªäœã§ãã
- ãã¹ããªãã
- ãã«ãã¹ã¬ãããªãã
ãã¡ã€ãã©ã€ãºã®äºå®ïŒ
- Redisãªã©ã®NoSQLããŒã¿ããŒã¹ãè©ŠããŠãã ããã
- åå¥ã®ãã£ã³ãã«ã«ãŒã ã
- ããŠã³ããŒãå¯èœãªã¢ãã¿ãŒã
- ããŸããŸãªçš®é¡ã®éç¥ãèšå®ããŸãã
- ãŠãŒã¶ãŒã«å人çãªã¡ã¢ãèšå®ããŸãã
- ãã©ã€ããŒããã£ã³ãã«ã§ã®ãä»ããå°å·ãã®è¡šç€ºã
ãããžã§ã¯ãéçºã®2ãæåŸã«ã©ã®ãããªçµè«ãå°ãåºãããšãã§ããŸããïŒ PHPã«ã¯ãŸã å¯èœæ§ããããŸãã å°ãªããšããã€ãã³ãæåã®ãã©ãã€ã ã䜿çšããäœæ¥ã®éå§ã¯æºåãããŸããã ããããæ²ããããªããããŸã§ã®ãšãããèšèªã¯è¿œãã€ããŠãéåã®é ã«ãªãããšããŠããŸããã ã©ãã§ãããšãã«ããŒããæ¯èŒãããšãèœåã®é¢ã§ã¯ãŸã åçã§ã¯ãããŸããã ãã®æ¹åã§ã®éçºãç©æ¥µçã«å éããç¶ããããšãæåŸ ããŸãããã
奜å¥å¿Forçãªäººã®ããã«ããããžã§ã¯ãã®ãœãŒã¹ã³ãŒãã¯ãã¡ãã«ãããŸã ã
建èšçãªã³ã¡ã³ããæè¿ããŸãã
PS
Node.jsãšReactPHPã®ããã©ãŒãã³ã¹æ¯èŒèšäº ã
Socket2httpãããã·ã®äŸ ã