| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> php >> PHP的Socket函数参考 PHP de Socket han shu shen kao
 

PHP的Socket函数参考

2008-12-19 08:07:32 编辑來源:互联网 繁體版 评论
 
 
本文为【PHP的Socket函数参考】的汉字拼音对照版显示拼音
  zhexieSockethanshuzhijiegenhulianwangdexieyijinxingfasongxinxixiangduiyufopensockdeliulaijiang,tamencaozuozaiyigebijiaodicengdejibietongchangtamendoushiduiC hanshujinxingfengzhuangbingqiemingchengdouleisiruguoniyou使shiyongCjinxingsocketbianchengdejingyanname使shiyongzhexiehanshujiangshifeichangshuliandewomenzhelibutaoluntebiexiangxidesocketbiancheng

  使shiyongzhexiehanshunenggoujiejuegaocengjibiehanshusuobunengjiejuedenanti使shiyongzhexiehanshunenggoushixianleisifopendegongnengniyexuyouhenduofangfalaishixiansocketdegongnengbiruzaiPHPzhong使shiyongCLICommand-line InterfacelaishixiandeInternetshouhujincheng

  resource socket_accept(resource socket)

  zainidejiaobenfuwuqiduanzhong使shiyongsocket_acceptjieshouyigejinrudelianjienibixushouxianchanshengyigesocketbangdingtadaoyigemingzibingqieshezhitajiantingyigeduankouzaikuaimoshizhongsocket_acceptjiangchanshengyigeweiyijieshouhoudelianjiezaifeikuaimoshizhongtameiyoujianlilianjiezefanhuifalselingwaidangniyouleyigexindesocketziyuanhoujiunenggoujinxingduxiecaozuo

  xiamianwomenjiangshifanyigejiandandehuixianfuwuqiduantayunxingzaiCLIminglingxingxiamiantazai12345duankoudengdaikehuduandelianjie

  socket_accept

  <?php

   set_time_limit(0);

   //create the socket

   if(($socket = socket_create(AF_INET, SOCK_STREAM, 0)) < 0){

   print("Couldn't create socket: " . socket_strerror(socket_last_error()) . "\n");

   }

   //bind it to the given address and port

   if(($error = socket_bind($socket, gethostbyname($_SERVER['HOSTNAME']), 12345)) < 0){

   print("Couldn't bind socket: " . socket_strerror(socket_last_error()) . "\n");

   }

   if(($error = socket_listen($socket, 5)) < 0){

   print("Couldn't list on socket: " .

   socket_strerror(socket_last_error()) . "\n");

   }

   while(TRUE){

   //wait for connection

   if(($accept = socket_accept($socket)) < 0){

   print("Error while reading: " . socket_strerror($message) . "\n");

   break;

   }

   //send welcome message

   socket_write($accept, "Connection accepted\n");

   print(date('Y-m-d H:i:s') . " STATUS: Connection accepted\n");

   ob_flush();

   while(TRUE){

   //read line from client

   if(FALSE === ($line = socket_read($accept, 1024))){

   print("Couldn't read from socket: " .

   socket_strerror(socket_last_error()) . "\n");

   break 2;

   }

   if(accept]!@socket_write($accept, "ECHO: $line")){

   print(date('Y-m-d H:i:s') . " STATUS: Connection interrupted\n");

   break;

   }

   print(date('Y-m-d H:i:s') . " READ: $line");

   ob_flush();

   }

   socket_close($accept);

   }

  ?>

  bool socket_bind(resource socket, string address, integer port)

  zhegesocket_bind()bayigesocketziyuanbangdingzaiyigedizhishangzhegesocketbixuyousocket_create()hanshufanhuideyigeziyuanzhegedizhibixushiyigeIPdizhihuozheshiyigebaocunUnix socketdelujingruguoshiyunxingzaiInternetshangdesocketnihuanbixutigongyigeduankou

  socket_clear_error(resource socket)

  zhegehanshunenggouqingchuzhidingsocketdecuowuruguomeiyouzhidingshenshunamejiangqingchusuoyousocketdecuowu

  socket_close(resource socket)

  socket_closehanshuguanbiyigesocketbingqieqingchugaisocketsuozhanyongdeneicunziyuan

  boolean socket_connect(resource socket, string address, integer port)

  zhegehanshuchuangjianyigekehuduandaoyigeduankouhuozhesocketdelianjienibixutigongyigeyousocket_createchanshengdesocketzhegeaddressshenshubixudaoyigesocketdelujinghuozheshiyigeIPdizhiruguoshihouzhehuanbixugenyigeshuzideduankouhao

  xiamianliziyanshile使shiyongUDPxieyidelianjiedaoyouxifuwuqiranhouhuoquxinxideguocheng

  socket_connect

  <?php

   //create UDP socket

   if(($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) < 0){

   print("Couldn't create socket: " .

   socket_strerror(socket_last_error()) . "\n");

   }

   //timeout after 5 seconds

   socket_set_option($socket, SOL_SOCKET,

   SO_RCVTIMEO, array('sec'=>5,'usec'=>0));

   //connect to the RtCW master server

   if(!socket_connect($socket, 'wolfmaster.idsoftware.com', 27950)){

   print("Couldn't connect: " .

   socket_strerror(socket_last_error()) . "\n");

   }

   //send request for servers

   socket_write($socket, "\xFF\xFF\xFF\xFFgetservers\x00");

   //get servers

   $server = array();

   while(FALSE !== ($line = @socket_read($socket, 4096))){

   //parse data

   for($i=22; ($i+5) < strlen($line); $i += 7){

   $ip = ord(substr($line, $i+1, 1)) . '.' .

   ord(substr($line, $i+2, 1)) . '.' .

   ord(substr($line, $i+3, 1)) . '.' .

   ord(substr($line, $i+4, 1));

   $port = (ord(substr($line, $i+5, 1)) * 256) +

   ord(substr($line, $i+6, 1));

   $server[] = array('ip'=>$ip, 'port'=>$port);

   }

   }

   print("<h1>" . count($server) . " Servers</h1>\n");

   //loop over servers, getting status

   foreach($server as $s){

   print("<h1>{$s['ip']}:{$s['port']}</h1>\n");

   //connect to RtCW server

   if(!socket_connect($socket, $s['ip'], $s['port'])){

   print("<p>\n" .

   socket_strerror(socket_last_error()) .

   "\n</p>\n");

   continue;

   }

   //send request for status

   socket_write($socket, "\xFF\xFF\xFF\xFFgetstatus\x00");

   //get status from server

   if(FALSE === ($line = @socket_read($socket, 1024))){

   print("<p>\n" .

   socket_strerror(socket_last_error()) .

   "\n</p>\n");

   continue;

   }

   $part = explode("\n", $line);

   //settings are in second line separated by backslashes

   $setting = explode("\\", $part[1]);

   print("<h2>Configuration</h2>\n");

   print("<p>\n");

   for($s=1; $s < count($setting); $s += 2){

   print("\t\t{$setting[$s]} = {$setting[$s+1]}<br>\n");

   }

   print("</p>\n");

   print("<h2>Players</h2>\n");

   $lastPlayer = count($part) - 1;

   for($p=2; $p < $lastPlayer; $p++){

   $player = explode(" ", $part[$p]);

   print("{$player[2]} Score={$player[0]} " .

   "Ping={$player[1]}<br>\n");

   }

   print("</p>\n");

   ob_flush();

   }

   print("</table>\n");

   socket_close($socket);

  ?>

  resource socket_create(integer family, integer socket_type, integer protocol)

  socket_createchushihuayigesocketdejiegoudiyigeshenshushiyigeprotocol familyhuozheyunibixu使shiyongAF_INETlaizhidingyigeInternetlianjiehuozhe使shiyongAF_UNIXlaizhidingyigeUnix socketlianjiediergeshenshushiyigesocketdeleixingnikeyicongxiamiandebiaozhongxuanzeyibanqingkuangxia使shiyongSOCK_STREAMlai使shiyongTCPxieyiUDPxieyi使shiyongSOCK_DGRAMdisangeshenshuzhidingweiyigexieyi使shiyongSOL_TCPhuoSOL_UDPlaifenbieduiyingTCPheUDPxieyihuanyouyigexuanzeshininenggou使shiyong getprotobynamehanshulaichuli

  Socket leixing

  changliang miaoshu

  SOCK_DGRAM zidongxunzhishujubaosocket

  SOCK_RAW RAWxieyijiekou

  SOCK_RDM kekaojiaohuanxiaoxi

  SOCK_SEQPACKET shunxushujubaosocket

  SOCK_STREAM liusocket

  resource socket_create_listen(integer port, integer backlog)

  使shiyongsocket_create_listenshiyizhongbisocket_creategengjiandandechanshengyigesocketjinxingjiantingzhegechanshengdesocketjiangjiantingzhidingdeduankouhoumiankexuandeshenshubacklogshishezhiyuanxuzuidadelianjieshu

  boolean socket_create_pair(integer family, integer socket_type, integer protocol, array handles)

  socket_create_pairhanshuchanshengyiduisocketlianjieshouxianqiansangeshenshushiduiyigesocket_createdemiaoshuzhegehandlesshenshushiyigebaohanlianggesocketziyuandeshuzugaihanshushiduiClimiansocketpairhanshudefengzhuang

  socket_create_pair

  <?php

   if(!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $socket)){

   print("Couldn't make sockets!\n");

   exit();

   }

   $child = pcntl_fork();

   if($child == -1){

   print("Couldn't fork!\n");

   exit();

   }

   elseif($child > 0){

   //parent

   socket_close($socket[0]);

   print("Parent: waiting for message\n");

   $message = socket_read($socket[1], 1024, PHP_NORMAL_READ);

   print("Parent: got message--$message\n");

   socket_write($socket[1], "Hello, Child Process!\n");

   pcntl_waitpid($child, $status);

   }else{

   //child

   socket_close($socket[1]);

   socket_write($socket[0], "Hello, Parent Process!\n");

   print("Child: waiting for message\n");

   $message = socket_read($socket[0], 1024, PHP_NORMAL_READ);

   print("Child: got message--$message\n");

   exit(0);

   }

  ?>

  value socket_get_option(resource socket, integer level, integer option)

  socket_get_optionhanshufanhuiyigexiabiaozhongsuoliedeyigetianjiazhinibixutigongyigeyousocket_createchanshengdesocketziyuanheyigedengjizhegehuoqudesocketjibiekeyi使shiyongSOL_SOCKETlaiquedingzhegejibieshenshulingwai使shiyongxieyibiruxiangSOL_TCPlaibiaoshiyigeTCPxieyizhexiexuanxiangkenengshiyousocket_set_optionshezhide

  socket_get_options

  <?php

   $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

   print('SO_BROADCAST: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_BROADCAST) . "<br>\n");

   print('SO_DEBUG: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_DEBUG) . "<br>\n");

   print('SO_DONTROUTE: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_DONTROUTE) . "<br>\n");

   print('SO_ERROR: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_ERROR) . "<br>\n");

   print('SO_KEEPALIVE: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_KEEPALIVE) . "<br>\n");

   print('SO_LINGER: ' .

   print_r(socket_get_option($socket, SOL_SOCKET,

   SO_LINGER), TRUE) . "<br>\n");

   print('SO_OOBINLINE: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_OOBINLINE) . "<br>\n");

   print('SO_RCVBUF: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_RCVBUF) . "<br>\n");

   print('SO_RCVLOWAT: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_RCVLOWAT) . "<br>\n");

   print('SO_RCVTIMEO: ' .

   print_r(socket_get_option($socket, SOL_SOCKET,

   SO_RCVTIMEO), TRUE) . "<br>\n");

   print('SO_REUSEADDR: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_REUSEADDR) . "<br>\n");

   print('SO_SNDBUF: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_SNDBUF) . "<br>\n");

   print('SO_SNDLOWAT: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_SNDLOWAT) . "<br>\n");

   print('SO_SNDTIMEO: ' .

   print_r(socket_get_option($socket, SOL_SOCKET,

   SO_SNDTIMEO), TRUE) . "<br>\n");

   print('SO_TYPE: ' .

   socket_get_option($socket, SOL_SOCKET,

   SO_TYPE) . "<br>\n");

  ?>

  Socketxuanxiangbiao

  xuanxiang miaoshu

  SO_BROADCAST yuanxuzidongxunzhidesocketfasonghejieshou广guangbobao

  SO_DEBUG dakaisockettiaoshigongnengzhiyourootcaiyouquanxiandakaigaixuanxiang

  SO_DONTROUTE bujieshouluyoubaotongguowangguan

  SO_ERROR huoqubingqieqingchuzuihouyicidesocketcuowuzhegexuanxiangyexubuyongshezhi

  SO_KEEPALIVE dakaibaochijihuozhuangtaidexiaoxi

  SO_LINGER Socket_colsehesocket_shutdowndezhongzhixiaoxifasongchaoshigaixuanxiang使shiyongyigeshuzubaokuol_onoffhel_lingerlianggejian

  SO_OOBINLINE bashujuzhijiecharudaojieshouhuanchong

  SO_RCVBUF xianzhijieshouhuanchongdezuidazijie

  SO_RCVLOWAT yanchitongguojieshouyigezuixiaodeshuju

  SO_RCVTIMEO yanchibaogaoyigejieshouchaoshibaogao使shiyongshuzudelianggejiansecheusec

  SO_REUSEADDR yuanxuchongxin使shiyongbendidizhi

  SO_SNDBUF xianzhifasonghuanchongdezuidazijie

  SO_SNDLOWAT yanchifasongshujudaozhegexieyidangjieshouyigezuixiaodezijie

  SO_SNDTIMEO yanchibaogaochaoshicuowudangfasongfasongtongguoyigeshijiangaixuanxiang使shiyongshuzudejianzhisecheusec

  SO_TYPE huoqusocketdeleixinggaixuanxiangkenengbuyongshezhi

  boolean socket_getpeername(resource socket, string address, integer port)

  socket_getpeernamecongzhidingdeyigelianjiezhonghuoqudizhiheduankouruguolianjieweiUnix socketnamejiangfanhuiwenjianxitongdelujing

  boolean socket_getsockname(resource socket, string address, integer port)

  socket_getsocknamefangzhiyigemingzidaosocketzhongbingqiejiashangaddressheportshenshushibaifanhuifalse

  (xiamiandesocket_iovec_* hanshubutailejiebuganluanfanyibaoliuyuanwen)

  boolean socket_iovec_add(resource iovector, integer length)

  The socket_iovec_add unction adds an I/O vector to the scatter/gather array.

  resource socket_iovec_alloc(integer count, )

  The socket_iovec_alloc function returns a resource for handling a collection of I/O vectors. The first argument specifies the number of vectors. Following arguments specify the length of each vector.

  boolean socket_iovec_delete(resource iovector, integer position)

  The socket_iovec_delete function removes the I/O vector at the given position.

  string socket_iovec_fetch(resource iovector, integer position)

  The socket_iovec_fetch function returns the value of the specified vector in the I/O vector resource.

  boolean socket_iovec_free(resource iovector)

  The socket_iovec_free function frees the memory used for an I/O vector resource.

  boolean socket_iovec_set(resource iovector, integer position, string value)

  The socket_iovec_set sets the value of I/O vector at the given position.

  integer socket_last_error(resource socket)

  socket_last_errorhanshufanhuicaozuozhongderenhesockethanshuchanshengdezuihoucuowuniyexuzaishangmianhanshuzhongshezhilesocketziyuande socketxuanxiangzaizhidingdelianjieshangxiamiandebiaoliechulefanhuidecuowudaimanitongyangkeyi使shiyongsoclet_strerrorhanshulaihuoquxiangxidecuowu使shiyong socket_clear_errorhanshuqingchusocketdecuowu

  Socketcuowudaimabiao

  changliang miaoshu

  SOCKET_E2BIG shenshuliebiaotaichang

  SOCKET_EACCES meiyouxukequanxian

  SOCKET_EADDRINUSE dizhiyijingbei使shiyong

  SOCKET_EADDRNOTAVAIL bunengjiexiqingqiudedizhi

  SOCKET_EADV 广guangbo广guanggaocuowu

  SOCKET_EAFNOSUPPORT Address familybuzhichidexieyi

  SOCKET_EAGAIN ziyuanzanshibunenghuode

  SOCKET_EALREADY caozuoyijingzaizhixing

  SOCKET_EBADE wuxiaodejiaohuan

  SOCKET_EBADF cuowudewenjianmiaoshufu

  SOCKET_EBADFD wenjianmiaoshufucuowudezhuangtai

  SOCKET_EBADMSG cuowudexiaoxi

  SOCKET_EBADR wuxiaodeqingqiumiaoshu

  SOCKET_EBADRQC wuxiaodeqingqiudaima

  SOCKET_EBADSLT wuxiaodecaozuoweizhi

  SOCKET_EBUSY qudonghuoziyuanfanmang

  SOCKET_ECHRNG xindaohaomachaochufanwei

  SOCKET_ECOMM fasongtongxuncuowu

  SOCKET_ECONNABORTED ruanjianyuanyindaozhitongxingzhongduan

  SOCKET_ECONNREFUSED lianjiebeijujue

  SOCKET_ECONNRESET lianjiebeixiangtongdesocketchongzhi

  SOCKET_EDESTADDRREQ bixuxuyaomubiaodizhi

  SOCKET_EDQUOT chaochucipanpeie

  SOCKET_EEXIST wenjianyicunzai

  SOCKET_EFAULT cuowudedizhi

  SOCKET_EHOSTDOWN zhujiyiguanbi

  SOCKET_EHOSTUNREACH meiyouluyoudaozhuji

  SOCKET_EIDRM biaoshiIDbeishanchu

  SOCKET_EINPROGRESS caozuozhengzaizhixing

  SOCKET_EINTR xitongtiaoyongbeizuzhi

  SOCKET_EINVAL wuxiaodeshenshu

  SOCKET_EIO shuru/ shuchucuowu

  SOCKET_EISCONN chuanshuzhongduanyijinglianjie

  SOCKET_EISDIR shiyigemulu

  SOCKET_EISNAM shiyigezhidingdeleixingwenjian

  SOCKET_EL2HLT jibie2yizhongzhi

  SOCKET_EL2NSYNC jibie2butongbu

  SOCKET_EL3HLT jibie3yizhongzhi

  SOCKET_EL3RST jibie3beichongzhi

  SOCKET_ELNRNG lianjiehaochaochufanwei

  SOCKET_ELOOP taiduojibiedefuhaolianjie

  SOCKET_EMEDIUMTYPE cuowudemeijieleixingzhongjianleixing

  SOCKET_EMFILE taiduodakaidewenjian

  SOCKET_EMLINK taiduodelianjie

  SOCKET_EMSGSIZE xiaoxitaichang

  SOCKET_EMULTIHOP changshicishutaiduo

  SOCKET_ENAMETOOLONG wenjianmingtaichang

  SOCKET_ENETDOWN wangluoyiguanbi

  SOCKET_ENETRESET wangluozhongduanlianjiebeichongzhi

  SOCKET_ENETUNREACHwangluobukeda

  SOCKET_ENFILE xitongzhongtaiduodakaidewenjian

  SOCKET_ENOANO meiyouzhengji

  SOCKET_ENOBUFS meiyoukeyongdehuancunkongjian

  SOCKET_ENOCSI meiyoukeyongdeCSIjiegou

  SOCKET_ENODATA meiyoukeyongdeshuju

  SOCKET_ENODEV meiyouzheyangdequdong

  SOCKET_ENOENT meiyouzheyangdewenjianhuomulu

  SOCKET_ENOLCK meiyoukeyongdejilusuo

  SOCKET_ENOLINK yijingyoudefuwudelianjie

  SOCKET_ENOMEDIUM meiyoumeijiebeizhaodao

  SOCKET_ENOMEM bunengfenpeineicun

  SOCKET_ENOMSG meiyouzhidingdexiaoxileixing

  SOCKET_ENONET shebeibuzaiwangluoshang

  SOCKET_ENOPROTOOPT xieyibukeyong

  SOCKET_ENOSPC meiyoukongjianzaiqudongqi

  SOCKET_ENOSR chaochudeliuziyuan

  SOCKET_ENOSTR qudongbushiyigeliu

  SOCKET_ENOSYS hanshumeiyouzhixing

  SOCKET_ENOTBLK kuaiqudongshibixude

  SOCKET_ENOTCONN chuanshuzhongduanmeiyoulianjie

  SOCKET_ENOTDIR meiyouyigemulu

  SOCKET_ENOTEMPTY muluweikong

  SOCKET_ENOTSOCK Socketcaozuozaiyigefeisocketshang

  SOCKET_ENOTTY buxiangfudeIOkongzhiqi

  SOCKET_ENOTUNIQ zaiwangluoshangmingzibushiweiyide

  SOCKET_ENXIO meiyouzheyangdequdonghuodizhi

  SOCKET_EOPNOTSUPP caozuobuzhichi

  SOCKET_EPERM caozuobuyuanxu

  SOCKET_EPFNOSUPPORT Protocol familybuzhichi

  SOCKET_EPIPE shibaideguandao

  SOCKET_EPROTO xieyicuowu

  SOCKET_EPROTONOSUPPORT xieyibuzhichi

  SOCKET_EPROTOTYPE Socketshangxieyicuowudeleixing

  SOCKET_EREMCHG yuanchengdizhiyigaibian

  SOCKET_EREMOTE duixiangshiyuanchengde

  SOCKET_EREMOTEIO yuanchengI/Ocuowu

  SOCKET_ERESTART zhongduandexitongtiaoyongjiangyaochongxinkaishi

  SOCKET_EROFS wenjianxitongweizhidu

  SOCKET_ESHUTDOWN. chuanshuduandianzhongduanbunengfasong

  SOCKET_ESOCKTNOSUPPORT Socketleixingbuzhichi

  SOCKET_ESPIPE buhefadejiansuo

  SOCKET_ESTRPIPE liuguandaocuowu

  SOCKET_ETIME dingshiqidaoshi

  SOCKET_ETIMEDOUT lianjiechaoshi

  SOCKET_ETOOMANYREFS taiduolianjiewufajiehe

  SOCKET_EUNATCH wufafujiaxieyiqudong

  SOCKET_EUSERS taiduoyonghu

  SOCKET_EWOULDBLOCK ziyuanzanshiwufahuode

  SOCKET_EXDEV wuxiaodejiaochaqudonglianjie

  SOCKET_EXFULL jiaohuanyiman

  boolean socket_listen(resource socket, integer backlog)

  zhegesocket_listenhanshudengdaicongkehuduanguolaidelianjiebacklogshenshushezhiyuanxuzuiduodengdailianjiededuilieshu

  string socket_read(resource socket, integer length, integer type)

  socket_readhanshucongtedingdesocketzhongduquzhidingdezijieruguocuowufanhuifalsequeshengxiashicaiyongerjinzhianquandeduqumoshinikeyiwaizaideshezhitypeshenshuweiPHP_BINARY_READlaigaibianduqumoshiniyekeyibatypeshezhiweiPHP_NORMAL_READ

  boolean socket_readv(resource socket, resource iovector)

  socket_readvhanshubaduqudeshujucharudaoiovectorziyuanzhong

  integer socket_recv(resource socket, string buffer, integer length, integer flags)

  socket_recvhanshuduqushujucharudaohuanchongzhongLengthshenshushezhizuiduoduqudezijieshuflagshenshukeyi使shiyongMSG_OOBhuoMSG_PEEKhanshufanhuiduqudezijieshu

  integer socket_recvfrom(resource socket, string buffer, integer length, string host, integer port)

  socket_frcvfromhanshuduqushujucharudaohuancunzhongLengthshenshushezhihuoquzuiduoyuanxujieshoudezijieshushezhiflagsshenshukeyiweiMSG_OOB huo MSG_PEEKPHPshezhizhujiheduankoushenshushidangdezhinenggouhuoqucongzhujifachudeshuju

  boolean socket_recvmsg(resource socket, resource iovector, array control, integer length, integer flags, string host, integer port)

  socket_recvmsghanshucongsocketzhongduqushujubingqiecharudaoyigeI/OxiangliangziyuanzhongPHPshezhicontrolshenshushiyigejuyousangeyuansudelianheshuzucmsg_level, cmsg_type, he cmsg_dataLengthshenshushiyigefujiazaishujuzhongdeguanyuhuoqushujudechangdushenshuFlagsshenshushishezhiyuanxuzhihefanhuizhizaixiedeshijianPHPwufazhixingsuoyoudeshuchuchangliangPHPshezhihostheportshenshushidangdezhishiweilehuoqucongyuanchengzhujizhongfasongdeshuju

  Socket_slecthanshumeiyoufanyiyinweipacibudayi

  integer socket_select(array read, array write, array exception, integer timeout_seconds, integer timeout_microseconds)

  The socket_select function waits for changes to sockets. PHP watches the sockets given in the read array for new data coming in. PHP watches the streams given in the write array for being ready to accept more data. PHP watches the streams given in the exception argument for errors. If the number of seconds specified in the timeout_seconds argument passes, the function returns. Use the optional timeout_microseconds argument to specify a timeout less than 1 second.

  The socket_select function returns the number of sockets that changed or FALSE if an error occurred. If the call timed out, this function returns zero. It also modifies the given arrays so that they include only those sockets that changed.

  If you have no sockets of a particular type to watch, you may pass an empty array or a variable set to NULL.

  integer socket_send(resource socket, string buffer, integer length, integer flags)

  socket_sendhanshubaxieshujudaohuanchongzhongranhoucharudaolianjiezhongnibixuzhidingyigehuanchongzuidakexiezijieshunitongyangkeyishezhiflagsshenshuweikonghuozheweixiamianlianhechangliangzhongdeyigeMSG_DONTROUTEhe MSG_OOBhanshujieshufanhuiyijingxiedezijieshushibaifanhuifalse

  boolean socket_sendmsg(resource socket, resource iovector, integer flags, string address, integer port)

  socket_sendmsgchangshifasongshujudaoyigesockettashihewulianjiedesocketIovectorshenshushiyigetongguo socket_iovec_allochanshuchanshengdeziyuannibixuzhidingflagsshenshuweiNULL, MSG_DONTROUTE, MSG_OOB,huozheshilianggelianhechangliangniyingdangzhidingyigedizhiheyigeInternetqingqiudeduankou

  Socket_sendmsghanshufasongshujufanhuitruedanshibunengbaozhengshujuyidingdaoda

  integer socket_sendto(resource socket, string buffer, integer length, integer flags, string address, integer port)

  socket_sendtohanshuchangshixieshujudaobufferhuanchongzhongbingqiefasonggeiyigesockettashihedabufenwulianjiedesocketnibixuzhiding flagsweiNULLMSG_DONTROUTE,MSG_OOBhuozheshiyigelianggelianhechangliangnihuanyingdanzhidingdizhiheyigeqingqiudeduankou

  Socket_sendtohanshushujufasongchuqufanhuitruedanshibunengbaozhengshujuyidingdaoda

  boolean socket_set_block(resource socket)

  socket_set_blockhanshushezhisocketcharudaoyigekuaimoshizhongzheshiqueshengmoshizaikuaimoshizhongI/Ocaozuozhengduiyuyigewanchengdeqingqiu

  boolean socket_set_nonblock(resource socket)

  socket_set_nonblockhanshushezhisocketcharudaoyigefeikuaimoshizhongzaifeikuaimoshizhongI/Ocaozuomashangfanhuiji使shimeiyoushuju

  boolean socket_set_option(resource socket, integer level, integer option, integer value)

  socket_set_optionhanshugeisocketshezhiyigexuanxiangLevelshenshushezhiyigebiaozhijibiedechangliangyouxiaodezhibaokuoSOL_SOCKET, SOL_TCPheSOL_UDPOptionshenshubixupipeiwenzhangshangmiandeSocketxuanxiangbiaozhongdechangliang

  boolean socket_shutdown(resource socket, integer how)

  socket_shutdownhanshuguanbiyigeguanyuI/Odesocketshezhihowwei0zezhongzhijieshoushujushezhiwei1zetingzhifasongshujushezhiwei2zezhongzhierzhecaozuo

  string socket_strerror(integer error)

  socket_strerrorhanshufanhuiyigecuowuhaodexiangxicuowuxinxi

  integer socket_write(resource socket, string buffer, integer length)

  socket_writehanshuxieshujudaobufferhuanchongzhongranhoushuchudaosocketzhongnikeyizhidinglengthshenshulaizhidinghuanchongdezuidazijieshuzhegehanshutongchangqingkuangxiabisocket_sendgengfang便bian

  boolean socket_writev(resource socket, resource iovector)

  socket_writevhanshutongguoI/Oxiangliangxieshujudaoyigesocketzhong原文】【拼音
 
 
 
 
上一篇《PHP和C通过Socket通信--UDP篇》
下一篇《PHP字符串函数库》
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

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

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

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

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

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

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

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

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

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

 
 
这些Socket函数直接跟互联网的协议进行发送信息。相对于fopensock的流来讲,他们操作在一个比较底层的级别。通常,他们都是对C 函数进行封装,并且名称都类似。如果你有使用C进行socket编程的经验,那么使用这些函数将是非常熟练的。我们这里不讨论特别详细的socket编程。 使用这些函数能够解决高层级别函数所不能解决的难题。使用这些函数能够实现类似fopen的功能,你也许有很多方法来实现socket的功能,比如在PHP中使用CLI(Command-line Interface)来实现的Internet守护进程。 resource socket_accept(resource socket) 在你的脚本服务器端中,使用socket_accept接受一个进入的连接。你必须首先产生一个socket,绑定它到一个名字,并且设置它监听一个端口。在块模式中,socket_accept将产生一个唯一接受后的连接。在非块模式中,它没有建立连接则返回false。另外,当你有了一个新的socket资源后就能够进行读写操作。 下面我们将示范一个简单的回显服务器端。它运行在CLI(命令行)下面,它在12345端口等待客户端的连接。 socket_accept <?php set_time_limit(0); //create the socket if(($socket = socket_create(AF_INET, SOCK_STREAM, 0)) < 0){ print("Couldn't create socket: " . socket_strerror(socket_last_error()) . "\n"); } //bind it to the given address and port if(($error = socket_bind($socket, gethostbyname($_SERVER['HOSTNAME']), 12345)) < 0){ print("Couldn't bind socket: " . socket_strerror(socket_last_error()) . "\n"); } if(($error = socket_listen($socket, 5)) < 0){ print("Couldn't list on socket: " . socket_strerror(socket_last_error()) . "\n"); } while(TRUE){ //wait for connection if(($accept = socket_accept($socket)) < 0){ print("Error while reading: " . socket_strerror($message) . "\n"); break; } //send welcome message socket_write($accept, "Connection accepted\n"); print(date('Y-m-d H:i:s') . " STATUS: Connection accepted\n"); ob_flush(); while(TRUE){ //read line from client if(FALSE === ($line = socket_read($accept, 1024))){ print("Couldn't read from socket: " . socket_strerror(socket_last_error()) . "\n"); break 2; } if([url=mailto:!@socket_write($accept]!@socket_write($accept[/url], "ECHO: $line")){ print(date('Y-m-d H:i:s') . " STATUS: Connection interrupted\n"); break; } print(date('Y-m-d H:i:s') . " READ: $line"); ob_flush(); } socket_close($accept); } ?> bool socket_bind(resource socket, string address, integer port) 这个socket_bind()把一个socket资源绑定在一个地址上。这个socket必须由socket_create()函数返回的一个资源。这个地址必须是一个IP地址或者是一个保存Unix socket的路径。如果是运行在Internet上的socket,你还必须提供一个端口。 socket_clear_error(resource socket) 这个函数能够清除制定socket的错误,如果没有指定参数,那么将清除所有socket的错误。 socket_close(resource socket) socket_close函数关闭一个socket并且清除该socket所占用的内存资源。 boolean socket_connect(resource socket, string address, integer port) 这个函数创建一个客户端到一个端口或者socket的连接。你必须提供一个由socket_create产生的socket。这个address参数必须到一个socket的路径或者是一个IP地址。如果是后者,还必须跟一个数字的端口号。 下面例子演示了使用UDP协议的连接到游戏服务器然后获取信息的过程。 socket_connect <?php //create UDP socket if(($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) < 0){ print("Couldn't create socket: " . socket_strerror(socket_last_error()) . "\n"); } //timeout after 5 seconds socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>5,'usec'=>0)); //connect to the RtCW master server if(!socket_connect($socket, 'wolfmaster.idsoftware.com', 27950)){ print("Couldn't connect: " . socket_strerror(socket_last_error()) . "\n"); } //send request for servers socket_write($socket, "\xFF\xFF\xFF\xFFgetservers\x00"); //get servers $server = array(); while(FALSE !== ($line = @socket_read($socket, 4096))){ //parse data for($i=22; ($i+5) < strlen($line); $i += 7){ $ip = ord(substr($line, $i+1, 1)) . '.' . ord(substr($line, $i+2, 1)) . '.' . ord(substr($line, $i+3, 1)) . '.' . ord(substr($line, $i+4, 1)); $port = (ord(substr($line, $i+5, 1)) * 256) + ord(substr($line, $i+6, 1)); $server[] = array('ip'=>$ip, 'port'=>$port); } } print("<h1>" . count($server) . " Servers</h1>\n"); //loop over servers, getting status foreach($server as $s){ print("<h1>{$s['ip']}:{$s['port']}</h1>\n"); //connect to RtCW server if(!socket_connect($socket, $s['ip'], $s['port'])){ print("<p>\n" . socket_strerror(socket_last_error()) . "\n</p>\n"); continue; } //send request for status socket_write($socket, "\xFF\xFF\xFF\xFFgetstatus\x00"); //get status from server if(FALSE === ($line = @socket_read($socket, 1024))){ print("<p>\n" . socket_strerror(socket_last_error()) . "\n</p>\n"); continue; } $part = explode("\n", $line); //settings are in second line separated by backslashes $setting = explode("\\", $part[1]); print("<h2>Configuration</h2>\n"); print("<p>\n"); for($s=1; $s < count($setting); $s += 2){ print("\t\t{$setting[$s]} = {$setting[$s+1]}<br>\n"); } print("</p>\n"); print("<h2>Players</h2>\n"); $lastPlayer = count($part) - 1; for($p=2; $p < $lastPlayer; $p++){ $player = explode(" ", $part[$p]); print("{$player[2]} Score={$player[0]} " . "Ping={$player[1]}<br>\n"); } print("</p>\n"); ob_flush(); } print("</table>\n"); socket_close($socket); ?> resource socket_create(integer family, integer socket_type, integer protocol) socket_create初始化一个socket的结构。第一个参数是一个protocol family,或者域。你必须使用AF_INET来指定一个Internet连接,或者使用AF_UNIX来指定一个Unix socket连接。第二个参数是一个socket的类型,你可以从下面的表中选择。一般情况下,使用SOCK_STREAM来使用TCP协议,UDP协议使用SOCK_DGRAM。第三个参数指定为一个协议。使用SOL_TCP或SOL_UDP来分别对应TCP和UDP协议。还有一个选择是你能够使用 getprotobyname函数来处理。 Socket 类型 常量 描述 SOCK_DGRAM 自动寻址数据包socket SOCK_RAW RAW协议接口 SOCK_RDM 可靠交换消息 SOCK_SEQPACKET 顺序数据包socket SOCK_STREAM 流socket resource socket_create_listen(integer port, integer backlog) 使用socket_create_listen是一种比socket_create更简单的产生一个socket进行监听。这个产生的socket将监听指定的端口,后面可选的参数backlog是设置允许最大的连接数。 boolean socket_create_pair(integer family, integer socket_type, integer protocol, array handles) socket_create_pair函数产生一对socket连接。首先前三个参数是对一个socket_create的描述,这个handles参数是一个包含两个socket资源的数组。该函数是对C里面socketpair函数的封装。 socket_create_pair <?php if(!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $socket)){ print("Couldn't make sockets!\n"); exit(); } $child = pcntl_fork(); if($child == -1){ print("Couldn't fork!\n"); exit(); } elseif($child > 0){ //parent socket_close($socket[0]); print("Parent: waiting for message\n"); $message = socket_read($socket[1], 1024, PHP_NORMAL_READ); print("Parent: got message--$message\n"); socket_write($socket[1], "Hello, Child Process!\n"); pcntl_waitpid($child, $status); }else{ //child socket_close($socket[1]); socket_write($socket[0], "Hello, Parent Process!\n"); print("Child: waiting for message\n"); $message = socket_read($socket[0], 1024, PHP_NORMAL_READ); print("Child: got message--$message\n"); exit(0); } ?> value socket_get_option(resource socket, integer level, integer option) socket_get_option函数返回一个下表中所列的一个添加值,你必须提供一个由socket_create产生的socket资源和一个等级。这个获取的socket级别,可以使用SOL_SOCKET来确定这个级别参数。另外,使用协议,比如象SOL_TCP来表示一个TCP协议。这些选项可能是由socket_set_option设置的。 socket_get_options <?php $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); print('SO_BROADCAST: ' . socket_get_option($socket, SOL_SOCKET, SO_BROADCAST) . "<br>\n"); print('SO_DEBUG: ' . socket_get_option($socket, SOL_SOCKET, SO_DEBUG) . "<br>\n"); print('SO_DONTROUTE: ' . socket_get_option($socket, SOL_SOCKET, SO_DONTROUTE) . "<br>\n"); print('SO_ERROR: ' . socket_get_option($socket, SOL_SOCKET, SO_ERROR) . "<br>\n"); print('SO_KEEPALIVE: ' . socket_get_option($socket, SOL_SOCKET, SO_KEEPALIVE) . "<br>\n"); print('SO_LINGER: ' . print_r(socket_get_option($socket, SOL_SOCKET, SO_LINGER), TRUE) . "<br>\n"); print('SO_OOBINLINE: ' . socket_get_option($socket, SOL_SOCKET, SO_OOBINLINE) . "<br>\n"); print('SO_RCVBUF: ' . socket_get_option($socket, SOL_SOCKET, SO_RCVBUF) . "<br>\n"); print('SO_RCVLOWAT: ' . socket_get_option($socket, SOL_SOCKET, SO_RCVLOWAT) . "<br>\n"); print('SO_RCVTIMEO: ' . print_r(socket_get_option($socket, SOL_SOCKET, SO_RCVTIMEO), TRUE) . "<br>\n"); print('SO_REUSEADDR: ' . socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR) . "<br>\n"); print('SO_SNDBUF: ' . socket_get_option($socket, SOL_SOCKET, SO_SNDBUF) . "<br>\n"); print('SO_SNDLOWAT: ' . socket_get_option($socket, SOL_SOCKET, SO_SNDLOWAT) . "<br>\n"); print('SO_SNDTIMEO: ' . print_r(socket_get_option($socket, SOL_SOCKET, SO_SNDTIMEO), TRUE) . "<br>\n"); print('SO_TYPE: ' . socket_get_option($socket, SOL_SOCKET, SO_TYPE) . "<br>\n"); ?> Socket选项表 选项 描述 SO_BROADCAST 允许自动寻址的socket发送和接受广播包 SO_DEBUG 打开socket调试功能,只有root才有权限打开该选项 SO_DONTROUTE 不接受路由包通过网关 SO_ERROR 获取并且清除最后一次的socket错误,这个选项也许不用设置 SO_KEEPALIVE 打开保持激活状态的消息 SO_LINGER Socket_colse和socket_shutdown的中止消息发送超时,该选项使用一个数组,包括l_onoff和l_linger两个键。 SO_OOBINLINE 把数据直接插入到接受缓冲 SO_RCVBUF 限制接受缓冲的最大字节 SO_RCVLOWAT 延迟通过接受一个最小的数据 SO_RCVTIMEO 延迟报告一个接受超时报告,使用数组的两个键:sec和usec SO_REUSEADDR 允许重新使用本地地址 SO_SNDBUF 限制发送缓冲的最大字节 SO_SNDLOWAT 延迟发送数据到这个协议当接受一个最小的字节 SO_SNDTIMEO 延迟报告超时错误,当发送发送通过一个时间。该选项使用数组的键值:sec和usec SO_TYPE 获取socket的类型,该选项可能不用设置 boolean socket_getpeername(resource socket, string address, integer port) socket_getpeername从指定的一个连接中获取地址和端口。如果连接为Unix socket,那么将返回文件系统的路径。 boolean socket_getsockname(resource socket, string address, integer port) socket_getsockname放置一个名字到socket中,并且加上address和port参数。失败返回false。 (下面的socket_iovec_* 函数不太了解,不敢乱翻译,保留原文) boolean socket_iovec_add(resource iovector, integer length) The socket_iovec_add unction adds an I/O vector to the scatter/gather array. resource socket_iovec_alloc(integer count, …) The socket_iovec_alloc function returns a resource for handling a collection of I/O vectors. The first argument specifies the number of vectors. Following arguments specify the length of each vector. boolean socket_iovec_delete(resource iovector, integer position) The socket_iovec_delete function removes the I/O vector at the given position. string socket_iovec_fetch(resource iovector, integer position) The socket_iovec_fetch function returns the value of the specified vector in the I/O vector resource. boolean socket_iovec_free(resource iovector) The socket_iovec_free function frees the memory used for an I/O vector resource. boolean socket_iovec_set(resource iovector, integer position, string value) The socket_iovec_set sets the value of I/O vector at the given position. integer socket_last_error(resource socket) socket_last_error函数返回操作中的任何socket函数产生的最后错误。你也许在上面函数中设置了socket资源的 socket选项在指定的连接上。下面的表列出了返回的错误代码,你同样可以使用soclet_strerror函数来获取详细的错误。使用 socket_clear_error函数清除socket的错误。 Socket错误代码表 常量 描述 SOCKET_E2BIG 参数列表太长 SOCKET_EACCES 没有许可权限 SOCKET_EADDRINUSE 地址已经被使用 SOCKET_EADDRNOTAVAIL 不能解析请求的地址 SOCKET_EADV 广播(广告)错误 SOCKET_EAFNOSUPPORT Address family不支持的协议 SOCKET_EAGAIN 资源暂时不能获得 SOCKET_EALREADY 操作已经在执行 SOCKET_EBADE 无效的交换 SOCKET_EBADF 错误的文件描述符 SOCKET_EBADFD 文件描述符错误的状态 SOCKET_EBADMSG 错误的消息 SOCKET_EBADR 无效的请求描述 SOCKET_EBADRQC 无效的请求代码 SOCKET_EBADSLT 无效的操作位置 SOCKET_EBUSY 驱动或资源繁忙 SOCKET_ECHRNG 信道号码超出范围 SOCKET_ECOMM 发送通讯错误 SOCKET_ECONNABORTED 软件原因导致通行中断 SOCKET_ECONNREFUSED 连接被拒绝 SOCKET_ECONNRESET 连接被相同的socket重置 SOCKET_EDESTADDRREQ 必须需要目标地址 SOCKET_EDQUOT 超出磁盘配额 SOCKET_EEXIST 文件已存在 SOCKET_EFAULT 错误的地址 SOCKET_EHOSTDOWN 主机已关闭 SOCKET_EHOSTUNREACH 没有路由到主机 SOCKET_EIDRM 表示ID被删除 SOCKET_EINPROGRESS 操作正在执行 SOCKET_EINTR 系统调用被阻止 SOCKET_EINVAL 无效的参数 SOCKET_EIO 输入/ 输出错误 SOCKET_EISCONN 传输终端已经连接 SOCKET_EISDIR 是一个目录 SOCKET_EISNAM 是一个指定的类型文件 SOCKET_EL2HLT 级别2已中止 SOCKET_EL2NSYNC 级别2不同步 SOCKET_EL3HLT 级别3已中止 SOCKET_EL3RST 级别3被重置 SOCKET_ELNRNG 连接号超出范围 SOCKET_ELOOP 太多级别的符号连接 SOCKET_EMEDIUMTYPE 错误的媒介类型(中间类型) SOCKET_EMFILE 太多打开的文件 SOCKET_EMLINK 太多的连接 SOCKET_EMSGSIZE 消息太长 SOCKET_EMULTIHOP 尝试次数太多 SOCKET_ENAMETOOLONG 文件名太长 SOCKET_ENETDOWN 网络已关闭 SOCKET_ENETRESET 网络中断,连接被重置 SOCKET_ENETUNREACH网络不可达 SOCKET_ENFILE 系统中太多打开的文件 SOCKET_ENOANO 没有正极 SOCKET_ENOBUFS 没有可用的缓存空间 SOCKET_ENOCSI 没有可用的CSI结构 SOCKET_ENODATA 没有可用的数据 SOCKET_ENODEV 没有这样的驱动 SOCKET_ENOENT 没有这样的文件或目录 SOCKET_ENOLCK 没有可用的记录锁 SOCKET_ENOLINK 已经有的服务的连接 SOCKET_ENOMEDIUM 没有媒介被找到 SOCKET_ENOMEM 不能分配内存 SOCKET_ENOMSG 没有指定的消息类型 SOCKET_ENONET 设备不在网络上 SOCKET_ENOPROTOOPT 协议不可用 SOCKET_ENOSPC 没有空间在驱动器 SOCKET_ENOSR 超出的流资源 SOCKET_ENOSTR 驱动不是一个流 SOCKET_ENOSYS 函数没有执行 SOCKET_ENOTBLK 块驱动是必须的 SOCKET_ENOTCONN 传输终端没有连接 SOCKET_ENOTDIR 没有一个目录 SOCKET_ENOTEMPTY 目录为空 SOCKET_ENOTSOCK Socket操作在一个非socket上 SOCKET_ENOTTY 不相符的IO控制器 SOCKET_ENOTUNIQ 在网络上名字不是唯一的 SOCKET_ENXIO 没有这样的驱动或地址 SOCKET_EOPNOTSUPP 操作不支持 SOCKET_EPERM 操作不允许 SOCKET_EPFNOSUPPORT Protocol family不支持 SOCKET_EPIPE 失败的管道 SOCKET_EPROTO 协议错误 SOCKET_EPROTONOSUPPORT 协议不支持 SOCKET_EPROTOTYPE Socket上协议错误的类型 SOCKET_EREMCHG 远程地址已改变 SOCKET_EREMOTE 对象是远程的 SOCKET_EREMOTEIO 远程I/O错误 SOCKET_ERESTART 中断的系统调用将要重新开始 SOCKET_EROFS 文件系统为只读 SOCKET_ESHUTDOWN. 传输端点中断不能发送 SOCKET_ESOCKTNOSUPPORT Socket类型不支持 SOCKET_ESPIPE 不合法的检索 SOCKET_ESTRPIPE 流管道错误 SOCKET_ETIME 定时器到时 SOCKET_ETIMEDOUT 连接超时 SOCKET_ETOOMANYREFS 太多连接无法结合 SOCKET_EUNATCH 无法附加协议驱动 SOCKET_EUSERS 太多用户 SOCKET_EWOULDBLOCK 资源暂时无法获得 SOCKET_EXDEV 无效的交叉驱动连接 SOCKET_EXFULL 交换已满 boolean socket_listen(resource socket, integer backlog) 这个socket_listen函数等待从客户端过来的连接,backlog参数设置允许最多等待连接的队列数。 string socket_read(resource socket, integer length, integer type) socket_read函数从特定的socket中读取指定的字节,如果错误返回false。缺省下,是采用二进制安全的读取模式。你可以外在的设置type参数为PHP_BINARY_READ来改变读取模式。你也可以把type设置为PHP_NORMAL_READ。 boolean socket_readv(resource socket, resource iovector) socket_readv函数把读取的数据插入到iovector资源中。 integer socket_recv(resource socket, string buffer, integer length, integer flags) socket_recv函数读取数据插入到缓冲中。Length参数设置最多读取的字节数,flag参数可以使用MSG_OOB或MSG_PEEK。函数返回读取的字节数。 integer socket_recvfrom(resource socket, string buffer, integer length, string host, integer port) socket_frcvfrom函数读取数据插入到缓存中。Length参数设置获取最多允许接受的字节数。设置flags参数可以为MSG_OOB 或 MSG_PEEK。PHP设置主机和端口参数适当的值能够获取从主机发出的数据。 boolean socket_recvmsg(resource socket, resource iovector, array control, integer length, integer flags, string host, integer port) socket_recvmsg函数从socket中读取数据并且插入到一个I/O向量资源中。PHP设置control参数是一个具有三个元素的联合数组:cmsg_level, cmsg_type, 和 cmsg_data。Length参数是一个附加在数据中的关于获取数据的长度参数。Flags参数是设置允许值和返回值。在写的时间,PHP无法执行所有的输出常量。PHP设置host和port参数适当的值是为了获取从远程主机中发送的数据。 (Socket_slect函数没有翻译,因为怕词不达意) integer socket_select(array read, array write, array exception, integer timeout_seconds, integer timeout_microseconds) The socket_select function waits for changes to sockets. PHP watches the sockets given in the read array for new data coming in. PHP watches the streams given in the write array for being ready to accept more data. PHP watches the streams given in the exception argument for errors. If the number of seconds specified in the timeout_seconds argument passes, the function returns. Use the optional timeout_microseconds argument to specify a timeout less than 1 second. The socket_select function returns the number of sockets that changed or FALSE if an error occurred. If the call timed out, this function returns zero. It also modifies the given arrays so that they include only those sockets that changed. If you have no sockets of a particular type to watch, you may pass an empty array or a variable set to NULL. integer socket_send(resource socket, string buffer, integer length, integer flags) socket_send函数把写数据到缓冲中,然后插入到连接中。你必须指定一个缓冲最大可写字节数。你同样可以设置flags参数为空,或者为下面联合常量中的一个:MSG_DONTROUTE和 MSG_OOB。函数结束返回已经写的字节数,失败返回false。 boolean socket_sendmsg(resource socket, resource iovector, integer flags, string address, integer port) socket_sendmsg尝试发送数据到一个socket。它适合无连接的socket。Iovector参数是一个通过 socket_iovec_alloc函数产生的资源。你必须指定flags参数为:NULL, MSG_DONTROUTE, MSG_OOB,或者是两个联合常量。你应当指定一个地址和一个Internet请求的端口。 Socket_sendmsg函数发送数据返回true,但是不能保证数据一定到达。 integer socket_sendto(resource socket, string buffer, integer length, integer flags, string address, integer port) socket_sendto函数尝试写数据到buffer缓冲中,并且发送给一个socket。它适合大部分无连接的socket。你必须指定 flags为:NULL,MSG_DONTROUTE,MSG_OOB或者是一个两个联合常量。你还应但指定地址和一个请求的端口。 Socket_sendto函数数据发送出去返回true,但是不能保证数据一定到达。 boolean socket_set_block(resource socket) socket_set_block函数设置socket插入到一个块模式中,这是缺省模式。在块模式中,I/O操作正对于一个完成的请求。 boolean socket_set_nonblock(resource socket) socket_set_nonblock函数设置socket插入到意个非块模式中。在非块模式中,I/O操作马上返回,即使没有数据。 boolean socket_set_option(resource socket, integer level, integer option, integer value) socket_set_option函数给socket设置一个选项。Level参数设置一个标志级别的常量。有效的值包括:SOL_SOCKET, SOL_TCP和SOL_UDP。Option参数必须匹配文章上面的Socket选项表中的常量。 boolean socket_shutdown(resource socket, integer how) socket_shutdown函数关闭一个关于I/O的socket。设置how为0则中止接受数据,设置为1则停止发送数据,设置为2则中止二者操作。 string socket_strerror(integer error) socket_strerror函数返回一个错误号的详细错误信息。 integer socket_write(resource socket, string buffer, integer length) socket_write函数写数据到buffer缓冲中然后输出到socket中。你可以指定length参数来指定缓冲的最大字节数。这个函数通常情况下比socket_send更方便。 boolean socket_writev(resource socket, resource iovector) socket_writev函数通过I/O向量写数据到一个socket中。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
华丽的模特拍摄(8)
华丽的模特拍摄(7)
华丽的模特拍摄(6)
华丽的模特拍摄(5)
八里沟
朝阳宫
天下峨眉 云上金顶
老家(四)
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
©2005- 王朝网络 版权所有