| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> php >> zai php shang shi yong fork yi ji socket de sample

zai php shang shi yong fork yi ji socket de sample

2008-12-19 08:07:38 编辑來源:互联网 评论
 
 
 
本文为【在php上使用fork以及socket的sample】的拼音翻译版
  zui jin gang hao yu dao yi ge tou da de wen di xie le yan ge code rang da jia can kao yi xia ba
  jia li de mo xian AP gong neng bu tai hao , ta zhi ti gong ba wai bu zhen shi IP map dao Nat li mian de mou ge IP
  bu neng zhi ding mou ge port map dao mou ge na bu IP de Port
  ke shi wo yi jing ba wai bu de IP Map dao na bu de Linux Server shang ,
  dan shi wo you xiang cong wai bu shi yong VNC lian dao na bu de yi tai Windows dian nao 。
  suo yi jiu xie le yan ge cheng shi
  yuan li shi yan yang
  yan ge cheng shi hui zai Linux Server shang kai yi ge Port zuo Listen de dong zuo
  dang wai bu lian dao yan ge Port shi , cheng shi hui zai kai qi ling yi ge lian xian lian dao na bu Windows de VNC shang
  ba wai bu de feng bao yuan feng bu dong de diu dao VNC de lian xian shang , ran hou ba VNC lian xian chuan hui de zi liao yuan feng bu dong de zai diu hui wai bu de Port
  cheng shi ma :
  #!/usr/bin/php -q
  <?php
  $IP='192.168.1.1';//Windows dian nao de IP
  $Port='5900'; //VNC shi yong de Port
  $ServerPort='9999';//Linux Server dui wai shi yong de Port
  $RemoteSocket=false;// lian xian dao VNC de Socket
  functionSignalFunction&#40;$Signal&#41;
  &#123;
   // yan shi zhu Process de xun xi chu li han shu
  global$PID;//Child Process de PID
  switch &#40;$Signal&#41;
  &#123;
   caseSIGTRAP&#58;
   caseSIGTERM&#58;
   // shou dao ji shu cheng shi de Signal
   if&#40;$PID&#41;
   &#123;
   // song yi ge SIGTERM de xun hao ji Child gao su ta gan kuai ji shu diao lou
   posix_kill&#40;$PID,SIGTERM&#41;;
   // deng dai Child Process ji shu , bi mian zombie
   pcntl_wait&#40;$Status&#41;;
   &#125;
   // guan bi zhu Process kai qi de Socket
   DestroySocket&#40;&#41;;
   exit&#40;0&#41;; // ji shu zhu Process
  
  break;
   caseSIGCHLD&#58;
   /*
  dang Child Process ji shu diao shi ,Child hui song yi ge SIGCHLD xun hao ji Parrent
  dang Parrent shou dao SIGCHLD, jiu zhi dao Child Process yi jing ji shu lou , gai zuo yi xie
  ji shu de dong zuo */
   unset&#40;$PID&#41;; // jiang $PID qing kong , biao shi Child Process yi jing ji shu
   pcntl_wait&#40;$Status&#41;; // bi mian Zombie
  
  break;
   default&#58;
  &#125;
  &#125;
  functionChildSignalFunction&#40;$Signal&#41;
  &#123;
  // yan shi Child Process de xun xi chu li han shu
  switch &#40;$Signal&#41;
  &#123;
   caseSIGTRAP&#58;
   caseSIGTERM&#58;
  //Child Process shou dao ji shu de xun xi
   DestroySocket&#40;&#41;; // guan bi Socket
   exit&#40;0&#41;; // ji shu Child Process
   default&#58;
  &#125;
  &#125;
  functionProcessSocket&#40;$ConnectedServerSocket&#41;
  &#123;
  //Child Process Socket chu li han shu
  //$ConnectedServerSocket -> wai bu lian jin lai de Socket
  global$ServerSocket,$RemoteSocket,$IP,$Port;
  $ServerSocket=$ConnectedServerSocket;
  declare&#40;ticks = 1&#41;; // yan yi xing yi ding yao jia , bu ran mei ban fa she ding xun xi chu li han shu 。
  // she ding xun xi chu li han shu
  if&#40;!pcntl_signal&#40;SIGTERM, "ChildSignalFunction"&#41;&#41; return;
  if&#40;!pcntl_signal&#40;SIGTRAP, "ChildSignalFunction"&#41;&#41; return;
  // jian li yi ge lian xian dao VNC de Socket
  $RemoteSocket=socket_create&#40;AF_INET, SOCK_STREAM,SOL_TCP&#41;;
  // lian xian dao na bu de VNC
  @$RemoteConnected=socket_connect&#40;$RemoteSocket,$IP,$Port&#41;;
  if&#40;!$RemoteConnected&#41; return; // mo fa lian xian dao VNC ji shu
  // jiang Socket de chu li she ha Nonblock, bi mian cheng shi bei Block zhu
  if&#40;!socket_set_nonblock&#40;$RemoteSocket&#41;&#41; return;
  if&#40;!socket_set_nonblock&#40;$ServerSocket&#41;&#41; return;
  while&#40;true&#41;
  &#123;
  // yan bian wo men cai yong pooling de fang shi qu qu de zi liao
   $NoRecvData=false; // yan ge bian shu yong lai pan bie wai bu de lian xian shi fou you dou dao zi liao
   $NoRemoteRecvData=false;// yan ge bian shu yong lai pan bie VNC lian xian shi fou you dou dao zi liao
   @$RecvData=socket_read&#40;$ServerSocket,4096,PHP_BINARY_READ&#41;;
  // cong wai bu lian xian dou qu 4096 bytes de zi liao
   @$RemoteRecvData=socket_read&#40;$RemoteSocket,4096,PHP_BINARY_READ&#41;;
  // cong vnc lian xian lian xian dou qu 4096 bytes de zi liao
   if&#40;$RemoteRecvData===''&#41;
   &#123;
  //VNC lian xian zhong duan , gai ji shu lou
   echo"Remote Connection Close\n";
   return;
   &#125;
   if&#40;$RemoteRecvData===false&#41;
   &#123;
  /*
  you yu wo men shi cai yong nonblobk mo shi
  yan li de qing kuang jiu shi vnc lian xian mei you ke gong dou qu de zi liao
  */
   $NoRemoteRecvData=true;
  // qing chu diao Last Errror
   socket_clear_error&#40;$RemoteSocket&#41;;
   &#125;
   if&#40;$RecvData===''&#41;
   &#123;
  // wai bu lian xian zhong duan , gai ji shu lou
   echo"Client Connection Close\n";
   return;
   &#125;
   if&#40;$RecvData===false&#41;
   &#123;
  /*
  you yu wo men shi cai yong nonblobk mo shi
  yan li de qing kuang jiu shi wai bu lian xian mei you ke gong dou qu de zi liao
  */
   $NoRecvData=true;
  // qing chu diao Last Errror
   socket_clear_error&#40;$ServerSocket&#41;;
   &#125;
   if&#40;$NoRecvData&&$NoRemoteRecvData&#41;
   &#123;
  // ru guo wai bu lian xian yi ji VNC lian xian dou mei you zi liao ke yi dou qu shi ,
  // jiu rang cheng shi shui ge 0.1 miao , bi mian chang qi chan yong CPU zi yuan
   usleep&#40;100000&#41;;
  // shui xing hou , ji xu zuo pooling de dong zuo dou qu socket
   continue;
   &#125;
   //Recv Data
   if&#40;!$NoRecvData&#41;
   &#123;
  // wai bu lian xian dou qu dao zi liao
   while&#40;true&#41;
   &#123;
  // ba wai bu lian xian dou dao de zi liao , zhuan song dao VNC lian xian shang
   @$WriteLen=socket_write&#40;$RemoteSocket,$RecvData&#41;;
   if&#40;$WriteLen===false&#41;
   &#123;
  // you yu wang lu chuan shu de wen di , mu qian zan shi mo fa xie ru zi liao
  // xian shui ge 0.1 miao zai ji xu chang shi 。
   usleep&#40;100000&#41;;
   continue;
   &#125;
   if&#40;$WriteLen===0&#41;
   &#123;
  // yuan duan lian xian zhong duan , cheng shi gai ji shu le
   echo"Remote Write Connection Close\n";
   return;
   &#125;
  // cong wai bu lian xian dou qu de zi liao , yi jing wan quan song ji VNC lian xian shi , zhong duan yan ge hui quan 。
   if&#40;$WriteLen==strlen&#40;$RecvData&#41;&#41; break;
  // ru guo zi liao yi ci song bu wan jiu de chai cheng hao ji ci chuan song , zhi dao suo you de zi liao quan bu song chu ha zhi
   $RecvData=substr&#40;$RecvData,$WriteLen&#41;;
   &#125;
   &#125;
   if&#40;!$NoRemoteRecvData&#41;
   &#123;
  // yan bian shi cong VNC lian xian dou qu dao de zi liao , zai zhuan song hui wai bu de lian xian
  // yuan li gen shang mian cha bu duo bu zai zhui shu
   while&#40;true&#41;
   &#123;
   @$WriteLen=socket_write&#40;$ServerSocket,$RemoteRecvData&#41;;
   if&#40;$WriteLen===false&#41;
   &#123;
   usleep&#40;100000&#41;;
   continue;
   &#125;
   if&#40;$WriteLen===0&#41;
   &#123;
   echo"Remote Write Connection Close\n";
   return;
   &#125;
   if&#40;$WriteLen==strlen&#40;$RemoteRecvData&#41;&#41; break;
   $RemoteRecvData=substr&#40;$RemoteRecvData,$WriteLen&#41;;
   &#125;
   &#125;
  &#125;
  &#125;
  functionDestroySocket&#40;&#41;
  &#123;
  // yong lai guan bi yi jing kai qi de Socket
  global$ServerSocket,$RemoteSocket;
  if&#40;$RemoteSocket&#41;
  &#123;
  // ru guo yi jing kai qi VNC lian xian
  // zai Close Socket qian bi xu jiang Socket shutdown bu ran dui fang bu zhi dao ni yi jing guan bi lian xian le
   @socket_shutdown&#40;$RemoteSocket,2&#41;;
   socket_clear_error&#40;$RemoteSocket&#41;;
  // guan bi Socket
   socket_close&#40;$RemoteSocket&#41;;
  &#125;
  // guan bi wai bu de lian xian
  @socket_shutdown&#40;$ServerSocket,2&#41;;
  socket_clear_error&#40;$ServerSocket&#41;;
  socket_close&#40;$ServerSocket&#41;;
  &#125;
  // yan li shi zheng ge cheng shi de kai tou , cheng shi cong yan bian kai shi zhi xing
  // yan li shou xian zhi xing yi ci fork
  $PID=pcntl_fork&#40;&#41;;
  if&#40;$PID==-1&#41; die&#40;"could not fork"&#41;;
  // ru guo $PID bu ha 0 biao shi yan shi Parrent Process
  //$PID jiu shi Child Process
  // yan shi Parrent Process zi ji ji shu diao , rang Child cheng ha yi ge Daemon。
  if&#40;$PID&#41; die&#40;"Daemon PID&#58;$PID\n"&#41;;
  // cong yan bian kai shi , jiu shi Daemon mo shi zai zhi xing le
  // jiang mu qian de Process gen zhong duan ji tui chi cheng ha daemon mo shi
  if&#40;!posix_setsid&#40;&#41;&#41; die&#40;"could not detach from terminal\n"&#41;;
  // she ding daemon de xun xi chu li han shu
  declare&#40;ticks = 1&#41;;
  if&#40;!pcntl_signal&#40;SIGTERM, "SignalFunction"&#41;&#41; die&#40;"Error!!!\n"&#41;;
  if&#40;!pcntl_signal&#40;SIGTRAP, "SignalFunction"&#41;&#41; die&#40;"Error!!!\n"&#41;;
  if&#40;!pcntl_signal&#40;SIGCHLD, "SignalFunction"&#41;&#41; die&#40;"Error!!!\n"&#41;;
  // jian li wai bu lian xian de Socket
  $ServerSocket=socket_create&#40;AF_INET, SOCK_STREAM,SOL_TCP&#41;;
  // she ding wai bu lian xian jian ting de IP yi ji Port,IP lan wei she 0, biao shi jing ting suo you jie mian de IP
  if&#40;!socket_bind&#40;$ServerSocket,0,$ServerPort&#41;&#41; die&#40;"Cannot Bind Socket!\n"&#41;;
  // kai shi jian ting Port
  if&#40;!socket_listen&#40;$ServerSocket&#41;&#41; die&#40;"Cannot Listen!\n"&#41;;
  // jiang Socket she ha nonblock mo shi
  if&#40;!socket_set_nonblock&#40;$ServerSocket&#41;&#41; die&#40;"Cannot Set Server Socket to Block!\n"&#41;;
  // qing kong $PID bian shu , biao shi mu qian mei you ren he de Child Process
  unset&#40;$PID&#41;;
  while&#40;true&#41;
  &#123;
  // jin ru pooling mo shi , mei ge 1 miao zhong jiu qu jian cha you mei you lian xian jin lai 。
  sleep&#40;1&#41;;
  // jian cha you mei you lian xian jin lai
  @$ConnectedServerSocket=socket_accept&#40;$ServerSocket&#41;;
  if&#40;$ConnectedServerSocket!==false&#41;
  &#123;
  // you ren lian jin lai lou
  // qi shi yi ge Child Process yong lai chu li lian xian
   $PID=pcntl_fork&#40;&#41;;
   if&#40;$PID==-1&#41; die&#40;"could not fork"&#41;;
   if&#40;$PID&#41; continue;// yan shi daemon process, ji xu hui qu jian ting 。
   // yan li shi Child Process kai shi
   // zhi xing Socket li han shu
   ProcessSocket&#40;$ConnectedServerSocket&#41;;
  // chu li wan Socket hou , ji shu diao Socket
   DestroySocket&#40;&#41;;
  // ji shu Child Process
   exit&#40;0&#41;;
  &#125;
  &#125;
  ?>【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
zui jin gang hao yu dao yi ge tou da de wen di xie le yan ge code rang da jia can kao yi xia ba jia li de mo xian AP gong neng bu tai hao , ta zhi ti gong ba wai bu zhen shi IP map dao Nat li mian de mou ge IP bu neng zhi ding mou ge port map dao mou ge na bu IP de Port ke shi wo yi jing ba wai bu de IP Map dao na bu de [url=http://www.knowsky.com/javascript:;]Linux[/url] Server shang , dan shi wo you xiang cong wai bu shi yong VNC lian dao na bu de yi tai [url=http://www.knowsky.com/javascript:;]Windows[/url] dian nao 。 suo yi jiu xie le yan ge cheng shi yuan li shi yan yang yan ge cheng shi hui zai Linux Server shang kai yi ge Port zuo Listen de dong zuo dang wai bu lian dao yan ge Port shi , cheng shi hui zai kai qi ling yi ge lian xian lian dao na bu Windows de VNC shang ba wai bu de feng bao yuan feng bu dong de diu dao VNC de lian xian shang , ran hou ba VNC lian xian chuan hui de zi liao yuan feng bu dong de zai diu hui wai bu de Port cheng shi ma : #!/usr/bin/php -q <?php $IP='192.168.1.1';//Windows dian nao de IP $Port='5900'; //VNC shi yong de Port $ServerPort='9999';//Linux Server dui wai shi yong de Port $RemoteSocket=false;// lian xian dao VNC de Socket functionSignalFunction&#40;$Signal&#41; &#123; // yan shi zhu Process de xun xi chu li han shu global$PID;//Child Process de PID switch &#40;$Signal&#41; &#123; caseSIGTRAP&#58; caseSIGTERM&#58; // shou dao ji shu cheng shi de Signal if&#40;$PID&#41; &#123; // song yi ge SIGTERM de xun hao ji Child gao su ta gan kuai ji shu diao lou posix_kill&#40;$PID,SIGTERM&#41;; // deng dai Child Process ji shu , bi mian zombie pcntl_wait&#40;$Status&#41;; &#125; // guan bi zhu Process kai qi de Socket DestroySocket&#40;&#41;; exit&#40;0&#41;; // ji shu zhu Process break; caseSIGCHLD&#58; /* dang Child Process ji shu diao shi ,Child hui song yi ge SIGCHLD xun hao ji Parrent dang Parrent shou dao SIGCHLD, jiu zhi dao Child Process yi jing ji shu lou , gai zuo yi xie ji shu de dong zuo */ unset&#40;$PID&#41;; // jiang $PID qing kong , biao shi Child Process yi jing ji shu pcntl_wait&#40;$Status&#41;; // bi mian Zombie break; default&#58; &#125; &#125; functionChildSignalFunction&#40;$Signal&#41; &#123; // yan shi Child Process de xun xi chu li han shu switch &#40;$Signal&#41; &#123; caseSIGTRAP&#58; caseSIGTERM&#58; //Child Process shou dao ji shu de xun xi DestroySocket&#40;&#41;; // guan bi Socket exit&#40;0&#41;; // ji shu Child Process default&#58; &#125; &#125; functionProcessSocket&#40;$ConnectedServerSocket&#41; &#123; //Child Process Socket chu li han shu //$ConnectedServerSocket -> wai bu lian jin lai de Socket global$ServerSocket,$RemoteSocket,$IP,$Port; $ServerSocket=$ConnectedServerSocket; declare&#40;ticks = 1&#41;; // yan yi xing yi ding yao jia , bu ran mei ban fa she ding xun xi chu li han shu 。 // she ding xun xi chu li han shu if&#40;!pcntl_signal&#40;SIGTERM, "ChildSignalFunction"&#41;&#41; return; if&#40;!pcntl_signal&#40;SIGTRAP, "ChildSignalFunction"&#41;&#41; return; // jian li yi ge lian xian dao VNC de Socket $RemoteSocket=socket_create&#40;AF_INET, SOCK_STREAM,SOL_TCP&#41;; // lian xian dao na bu de VNC @$RemoteConnected=socket_connect&#40;$RemoteSocket,$IP,$Port&#41;; if&#40;!$RemoteConnected&#41; return; // mo fa lian xian dao VNC ji shu // jiang Socket de chu li she ha Nonblock, bi mian cheng shi bei Block zhu if&#40;!socket_set_nonblock&#40;$RemoteSocket&#41;&#41; return; if&#40;!socket_set_nonblock&#40;$ServerSocket&#41;&#41; return; while&#40;true&#41; &#123; // yan bian wo men cai yong pooling de fang shi qu qu de zi liao $NoRecvData=false; // yan ge bian shu yong lai pan bie wai bu de lian xian shi fou you dou dao zi liao $NoRemoteRecvData=false;// yan ge bian shu yong lai pan bie VNC lian xian shi fou you dou dao zi liao @$RecvData=socket_read&#40;$ServerSocket,4096,PHP_BINARY_READ&#41;; // cong wai bu lian xian dou qu 4096 bytes de zi liao @$RemoteRecvData=socket_read&#40;$RemoteSocket,4096,PHP_BINARY_READ&#41;; // cong vnc lian xian lian xian dou qu 4096 bytes de zi liao if&#40;$RemoteRecvData===''&#41; &#123; //VNC lian xian zhong duan , gai ji shu lou echo"Remote Connection Close\n"; return; &#125; if&#40;$RemoteRecvData===false&#41; &#123; /* you yu wo men shi cai yong nonblobk mo shi yan li de qing kuang jiu shi vnc lian xian mei you ke gong dou qu de zi liao */ $NoRemoteRecvData=true; // qing chu diao Last Errror socket_clear_error&#40;$RemoteSocket&#41;; &#125; if&#40;$RecvData===''&#41; &#123; // wai bu lian xian zhong duan , gai ji shu lou echo"Client Connection Close\n"; return; &#125; if&#40;$RecvData===false&#41; &#123; /* you yu wo men shi cai yong nonblobk mo shi yan li de qing kuang jiu shi wai bu lian xian mei you ke gong dou qu de zi liao */ $NoRecvData=true; // qing chu diao Last Errror socket_clear_error&#40;$ServerSocket&#41;; &#125; if&#40;$NoRecvData&&$NoRemoteRecvData&#41; &#123; // ru guo wai bu lian xian yi ji VNC lian xian dou mei you zi liao ke yi dou qu shi , // jiu rang cheng shi shui ge 0.1 miao , bi mian chang qi chan yong CPU zi yuan usleep&#40;100000&#41;; // shui xing hou , ji xu zuo pooling de dong zuo dou qu socket continue; &#125; //Recv Data if&#40;!$NoRecvData&#41; &#123; // wai bu lian xian dou qu dao zi liao while&#40;true&#41; &#123; // ba wai bu lian xian dou dao de zi liao , zhuan song dao VNC lian xian shang @$WriteLen=socket_write&#40;$RemoteSocket,$RecvData&#41;; if&#40;$WriteLen===false&#41; &#123; // you yu wang lu chuan shu de wen di , mu qian zan shi mo fa xie ru zi liao // xian shui ge 0.1 miao zai ji xu chang shi 。 usleep&#40;100000&#41;; continue; &#125; if&#40;$WriteLen===0&#41; &#123; // yuan duan lian xian zhong duan , cheng shi gai ji shu le echo"Remote Write Connection Close\n"; return; &#125; // cong wai bu lian xian dou qu de zi liao , yi jing wan quan song ji VNC lian xian shi , zhong duan yan ge hui quan 。 if&#40;$WriteLen==strlen&#40;$RecvData&#41;&#41; break; // ru guo zi liao yi ci song bu wan jiu de chai cheng hao ji ci chuan song , zhi dao suo you de zi liao quan bu song chu ha zhi $RecvData=substr&#40;$RecvData,$WriteLen&#41;; &#125; &#125; if&#40;!$NoRemoteRecvData&#41; &#123; // yan bian shi cong VNC lian xian dou qu dao de zi liao , zai zhuan song hui wai bu de lian xian // yuan li gen shang mian cha bu duo bu zai zhui shu while&#40;true&#41; &#123; @$WriteLen=socket_write&#40;$ServerSocket,$RemoteRecvData&#41;; if&#40;$WriteLen===false&#41; &#123; usleep&#40;100000&#41;; continue; &#125; if&#40;$WriteLen===0&#41; &#123; echo"Remote Write Connection Close\n"; return; &#125; if&#40;$WriteLen==strlen&#40;$RemoteRecvData&#41;&#41; break; $RemoteRecvData=substr&#40;$RemoteRecvData,$WriteLen&#41;; &#125; &#125; &#125; &#125; functionDestroySocket&#40;&#41; &#123; // yong lai guan bi yi jing kai qi de Socket global$ServerSocket,$RemoteSocket; if&#40;$RemoteSocket&#41; &#123; // ru guo yi jing kai qi VNC lian xian // zai Close Socket qian bi xu jiang Socket shutdown bu ran dui fang bu zhi dao ni yi jing guan bi lian xian le @socket_shutdown&#40;$RemoteSocket,2&#41;; socket_clear_error&#40;$RemoteSocket&#41;; // guan bi Socket socket_close&#40;$RemoteSocket&#41;; &#125; // guan bi wai bu de lian xian @socket_shutdown&#40;$ServerSocket,2&#41;; socket_clear_error&#40;$ServerSocket&#41;; socket_close&#40;$ServerSocket&#41;; &#125; // yan li shi zheng ge cheng shi de kai tou , cheng shi cong yan bian kai shi zhi xing // yan li shou xian zhi xing yi ci fork $PID=pcntl_fork&#40;&#41;; if&#40;$PID==-1&#41; die&#40;"could not fork"&#41;; // ru guo $PID bu ha 0 biao shi yan shi Parrent Process //$PID jiu shi Child Process // yan shi Parrent Process zi ji ji shu diao , rang Child cheng ha yi ge Daemon。 if&#40;$PID&#41; die&#40;"Daemon PID&#58;$PID\n"&#41;; // cong yan bian kai shi , jiu shi Daemon mo shi zai zhi xing le // jiang mu qian de Process gen zhong duan ji tui chi cheng ha daemon mo shi if&#40;!posix_setsid&#40;&#41;&#41; die&#40;"could not detach from terminal\n"&#41;; // she ding daemon de xun xi chu li han shu declare&#40;ticks = 1&#41;; if&#40;!pcntl_signal&#40;SIGTERM, "SignalFunction"&#41;&#41; die&#40;"Error!!!\n"&#41;; if&#40;!pcntl_signal&#40;SIGTRAP, "SignalFunction"&#41;&#41; die&#40;"Error!!!\n"&#41;; if&#40;!pcntl_signal&#40;SIGCHLD, "SignalFunction"&#41;&#41; die&#40;"Error!!!\n"&#41;; // jian li wai bu lian xian de Socket $ServerSocket=socket_create&#40;AF_INET, SOCK_STREAM,SOL_TCP&#41;; // she ding wai bu lian xian jian ting de IP yi ji Port,IP lan wei she 0, biao shi jing ting suo you jie mian de IP if&#40;!socket_bind&#40;$ServerSocket,0,$ServerPort&#41;&#41; die&#40;"Cannot Bind Socket!\n"&#41;; // kai shi jian ting Port if&#40;!socket_listen&#40;$ServerSocket&#41;&#41; die&#40;"Cannot Listen!\n"&#41;; // jiang Socket she ha nonblock mo shi if&#40;!socket_set_nonblock&#40;$ServerSocket&#41;&#41; die&#40;"Cannot Set Server Socket to Block!\n"&#41;; // qing kong $PID bian shu , biao shi mu qian mei you ren he de Child Process unset&#40;$PID&#41;; while&#40;true&#41; &#123; // jin ru pooling mo shi , mei ge 1 miao zhong jiu qu jian cha you mei you lian xian jin lai 。 sleep&#40;1&#41;; // jian cha you mei you lian xian jin lai @$ConnectedServerSocket=socket_accept&#40;$ServerSocket&#41;; if&#40;$ConnectedServerSocket!==false&#41; &#123; // you ren lian jin lai lou // qi shi yi ge Child Process yong lai chu li lian xian $PID=pcntl_fork&#40;&#41;; if&#40;$PID==-1&#41; die&#40;"could not fork"&#41;; if&#40;$PID&#41; continue;// yan shi daemon process, ji xu hui qu jian ting 。 // yan li shi Child Process kai shi // zhi xing Socket li han shu ProcessSocket&#40;$ConnectedServerSocket&#41;; // chu li wan Socket hou , ji shu diao Socket DestroySocket&#40;&#41;; // ji shu Child Process exit&#40;0&#41;; &#125; &#125; ?>
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
华丽的模特拍摄(8)
华丽的模特拍摄(7)
华丽的模特拍摄(6)
华丽的模特拍摄(5)
八里沟
朝阳宫
天下峨眉 云上金顶
老家(四)
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有