| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> php >> zai PHP zhong shi yong Sockets: cong Usenet zhong huo qu wen jian

zai PHP zhong shi yong Sockets: cong Usenet zhong huo qu wen jian

2008-12-22 08:09:21 编辑來源:互联网 评论
 
 
 
本文为【在PHP中使用Sockets:从Usenet中获取文件】的拼音翻译版
  zuo zhe :Armel Fauveau
  yuan wen di zhi :http://www.phpbuilder.net/columns/armel20010427.php3
  yi zhe : xu li qiang feifengxlq@gmail.com
Http://www.phpobject.net/blog/
  PHP neng gou da kai yuan cheng huo zhe ben di fu wu qi de sockets! zhe li shi yi ge shi yong socket de jian dan de li zi : lian jie dao Usenet de xin wen fu wu qi , yu fu wu qi gou tong , bing cong yi ge jing que de xin wen fen zu zhong xia zai yi xie wen zhang 。
  shi yong PHP da kai Socket
  shi yong fsockopen() lai da kai yi ge Socket。 zhe ge han shu zai PHP3 he PHP4 zhong dou cun zai 。 han shu de yuan xing ru xia :
  <?php
  intfsockopen
   (string hostname,
   int port[,
   int errno[,
   string errstr[,
   double timeout]]])
  ?>
  dui yu wang luo zhu ji , ta jiang jian li yi ge TCP de Socket de lian jie dao zhu ji ming de duan kou shang 。 zhu ji ming ke yi shi yu ming huo zhe IP di zhi 。 dui yu UDP lian jie , ni xu yao ming que zhi chu qi xie yi :udp://hostname。 dui yu unix zhu ji , zhu ji ming jiang zai socket de lu jing zhong shi yong , zai zhe ge li zi zhong duan kou bi xu she zhi cheng 0。 ke xuan xiang timeout ke yi yong lai she zhi lian jie chao shi de miao shu 。
  guan yu fsockopen() de geng duo xin xi ke yi fang wen http://www.php.net/manual/function.fsockopen.php
  wang luo xin wen chuan shu xie yi (NNTP)
  fang wen yi ge usenet xin wen fu wu qi xu yao yong dao yi ge te bie de xie yi , cheng zuo NNTP, ji wang luo xin wen chuan shu xie yi biao zhun 。 zhe ge xie yi de xiang xi zi liao zai RFC977 zhong , ni ke yi zai http://www.w3.org/Protocols/rfc977/rfc977.html zhong cha kan dao 。 zhe ge wen dang xiang xi de miao shu le ru he shi yong bu tong de ming ling lai lian jie bing qie he NNTP fu wu qi dui hua 。
  lian jie fu wu qi
  lian jie dao NNTP fu wu qi xu yao zhi dao fu wu qi de zhu ji ming ( huo zhe IP di zhi ) he ta jiang yao jian ting de duan kou 。 ling wai jian yi ni jia shang yi ge chao shi de shi jian , zhe yang lian jie shi bai de shi hou jiu bu hui “ dong jie ” cheng xu 。
  <?php
  $cfgServer ="your.news.host";
  $cfgPort =119;
  $cfgTimeOut =10;
  // open asocket
  if(!$cfgTimeOut)
   // without timeout
   $usenet_handle=fsockopen($cfgServer,$cfgPort);
  else
   // with timeout
   $usenet_handle=fsockopen($cfgServer,$cfgPort, &$errno, &$errstr,$cfgTimeOut);
  if(!$usenet_handle) {
   echo"Connexionfailed\n";
   exit();
  }
  else {
   echo"Connected\n";
   $tmp=fgets($usenet_handle,1024);
  }
  ?>
  yu fu wu qi jiao hu
  xian zai wo men yi jing lian jie shang fu wu qi le , er qie neng gou tong guo xian qian da kai de socket lian jie yu fu wu qi jin xing jiao hu 。 rang wo men dui fu wu qi shuo “ wo men yao cong mou yi xin wen fen zu zhong huo qu dao zui xin de 10 pian wen zhang ”。RFC977 ding yi le ru he xuan ze zheng que de xin wen fen zu de ming ling , ru xia :
  GROUPggg
  bi xu de shen shu ggg shi ni jiang yao xuan ze de xin wen fen zu de ming zi , bi ru net.news。 shi yong list ming ling ni ke yi huo qu dao yi zu you xiao de xin wen lie biao 。 cheng gong xuan ze xiang ying hui fan hui zu zhong shou yi liang pian xin wen de xin wen hao yi ji dui cun dang xin wen hao gu ji 。
  bi ru
  chrome:~$ telnetmy.news.host 119
  Trying aa.bb.cc.dd...
  Connected tomy.news.host.
  Escape character is'^]'.
  200 my.news.hostInterNetNews NNRP server INN 2.2.2 13-Dec-1999 ready (posting ok).
  GROUP alt.test
  211 232 222996 223235alt.test
  quit
  205 .
  zai jie shou dao ming ling “GROUP alt.test”, xin wen fu wu qi fan hui le “211232 222996 223235 alt.test”。 qi zhong 211 shi RFC biao shi ma ( jian dan de jie shi shuo ming ling yi jing cheng gong de zhi xing — cha kan RFC ni ke yi huo qu geng jia xiang xi de zi liao ), fan hui xin xi shuo ming qi zhong you 232 pian wen zhang , qi zhong zui jiu de xin wen de suo yin hao shi 222996, er zui xin de xin wen suo yin hao shi 223235。 xian zai rang wo men ji suan xia :222996+232 bing bu deng yu 232235。 zhe diu shi de wen zhang huo zhe cong zhe fu wu qi yi chu chu qu le , huo zhe bei ta de zuo zhe qu xiao le ( shi de , zhe shi ke neng de , ye shi hen rong yi shi xian de ), huo zhe shi shan chu le 。
  xiao xin qi jian , zai xuan ze xin wen fen zu zhi qian , fu wu qi ke neng xu yao ren zheng , dang ran zhe shi you fu wu qi shi fou gong kai huo zhe si you lai jue ding de 。 yi ban shi yuan xu ren he ren huo qu xin wen , dan fa biao xin wen xu yao tong guo ren zheng 。
  <?php
  //$cfgUser = "xxxxxx";
  //$cfgPasswd = "yyyyyy";
  $cfgNewsGroup ="alt.php";
  // identification required on private server
  if($cfgUser) {
   fputs($usenet_handle,"AUTHINFO USER".$cfgUser."\n");
   $tmp=fgets($usenet_handle,1024);
   fputs($usenet_handle,"AUTHINFOPASS".$cfgPasswd."\n");
   $tmp=fgets($usenet_handle,1024);
   // check error
   if($tmp!="281Ok\r\n") {
   echo"502Authentication error\n";
   exit();
   }
  }
  // select newsgroup
  fputs($usenet_handle,"GROUP ".$cfgNewsGroup."\n");
  $tmp=fgets($usenet_handle,1024);
  if($tmp=="480 Authentication required for command\r\n") {
   echo"$tmp\n";
   exit();
  }
  $info=split(" ",$tmp);
  $first=$info[2];
  $last=$info[3];
  print"First : $first\n";
  print"Last : $last\n";
  ?>
  huo qu yi xie wen zhang
  xian zai wo men yi jing you zui xin wen zhang de A suo yin hao , na jiu neng hen rong yi de huo qu zui xin de shi pian wen zhang 。RFC977 zhi chu shi yong ARTICLE ming ling ke yi he wen zhang de suo yin hao huo zhe xiao xi de ID yi qi shi yong 。 wei le xiao xin qi jian , zai zhe li , wen zhang de suo yin hao he xiao xi ID shi bu tong de , yin wei mei ge xin wen fu wu qi ding yi bu tong , suo yi zai bu tong de xin wen fu wu qi shang xiang tong wen zhang de suo yin hao dou hui bu yi yang de , dan shi xiao xi ID hao shi wei yi de ( bao han zai wen zhang de tou bu zhong )
  <?php
  $cfgLimit =10;
  // upload last articles
  $boucle=$last-$cfgLimit;
  while ($boucle<=$last) {
   set_time_limit(0);
   fputs($usenet_handle,"ARTICLE$boucle\n");
   $article="";
   $tmp=fgets($usenet_handle,4096);
   if(substr($tmp,0,3) !="220") {
   echo"+----------------------+\n";
   echo"Error onarticle $boucle\n";
   echo"+----------------------+\n";
   }
   else {
   while($tmp!=".\r\n") {
   $tmp=fgets($usenet_handle,4096);
   $article=$article.$tmp;
   }
   echo"+----------------------+\n";
   echo"Article$boucle\n";
   echo"+----------------------+\n";
   echo"$article\n";
   }
   $boucle++;
  }
  ?>
  wo men jin jin cong zhe ge fu wu qi de zhe ge fen zu shang huo qu le shi tiao zui xin de xin wen 。 ni ye ke yi shi yong HEAD ming ling lai zhi huo qu wen zhang de tou bu xin xi , huo zhe shi yong BODY ming ling lai huo qu xin wen de zheng wen 。
  guan bi lian jie
  shi yong fclose() han shu ni jiu ke yi jie shu yu NNTP fu wu qi zhi jian de hui hua , dang ran ni ke yi xie yi ge xin de wen jian , ru xia :
  <?php
  // close connexion
  fclose($usenet_handle);
  ?>
  geng duo guan yu fclose() de xin xi , qing kan :http://www.php.net/manual/function.fclose.php
  jie lun
  ben wen zhong , wo men zhi shuo ming le zai que ding de qing kuang xia ru he da kai 、 shi yong he guan bi yi ge socket lian jie : lian jie shang yi ge NNTP fu wu qi ran hou cong xin wen fen zu zhong qu hui yi xie wen zhang 。 shi yong POST ming ling zai NNTP fu wu qi shang fa biao yi pian wen zhang bing bu fu duo duo shao 。
  yin ci , xia yi bu jiu shi bian xie yi ge xin wen ke hu duan ( bing qu diao yi xie Netscape), ta xu yao neng hen rong yi de bao cun wen zhang , bing shi yong yi xie sou suo yin qing ( bi ru htgid,http://www.htdig.org/) lai suo yin zhe xie wen zhang , er qie yao you yi ge WEB ying yong cheng xu neng jin xing xin wen fen zu xia de guan jian zi sou suo 。 zhe li you yi ge li zi , ni ke yi fang wen http://www.phpindex.com/ng/ qu xia zai 。【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

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

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

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

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

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

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

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

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

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

 
 
zuo zhe :Armel Fauveau yuan wen di zhi :[url=http://www.phpbuilder.net/columns/armel20010427.php3]http://www.phpbuilder.net/columns/armel20010427.php3[/url] yi zhe : xu li qiang [url=mailto:feifengxlq@gmail.com]feifengxlq@gmail.com[/url] [url=http://www.phpobject.net/blog/]Http://www.phpobject.net/blog/[/url] PHP neng gou da kai yuan cheng huo zhe ben di fu wu qi de sockets! zhe li shi yi ge shi yong socket de jian dan de li zi : lian jie dao Usenet de xin wen fu wu qi , yu fu wu qi gou tong , bing cong yi ge jing que de xin wen fen zu zhong xia zai yi xie wen zhang 。 shi yong PHP da kai Socket shi yong fsockopen() lai da kai yi ge Socket。 zhe ge han shu zai PHP3 he PHP4 zhong dou cun zai 。 han shu de yuan xing ru xia : <?php intfsockopen (string hostname, int port[, int errno[, string errstr[, double timeout]]]) ?> dui yu wang luo zhu ji , ta jiang jian li yi ge TCP de Socket de lian jie dao zhu ji ming de duan kou shang 。 zhu ji ming ke yi shi yu ming huo zhe IP di zhi 。 dui yu UDP lian jie , ni xu yao ming que zhi chu qi xie yi :udp://hostname。 dui yu unix zhu ji , zhu ji ming jiang zai socket de lu jing zhong shi yong , zai zhe ge li zi zhong duan kou bi xu she zhi cheng 0。 ke xuan xiang timeout ke yi yong lai she zhi lian jie chao shi de miao shu 。 guan yu fsockopen() de geng duo xin xi ke yi fang wen [url=http://www.php.net/manual/function.fsockopen.php]http://www.php.net/manual/function.fsockopen.php[/url] wang luo xin wen chuan shu xie yi (NNTP) fang wen yi ge usenet xin wen fu wu qi xu yao yong dao yi ge te bie de xie yi , cheng zuo NNTP, ji wang luo xin wen chuan shu xie yi biao zhun 。 zhe ge xie yi de xiang xi zi liao zai RFC977 zhong , ni ke yi zai [url=http://www.w3.org/Protocols/rfc977/rfc977.html]http://www.w3.org/Protocols/rfc977/rfc977.html[/url] zhong cha kan dao 。 zhe ge wen dang xiang xi de miao shu le ru he shi yong bu tong de ming ling lai lian jie bing qie he NNTP fu wu qi dui hua 。 lian jie fu wu qi lian jie dao NNTP fu wu qi xu yao zhi dao fu wu qi de zhu ji ming ( huo zhe IP di zhi ) he ta jiang yao jian ting de duan kou 。 ling wai jian yi ni jia shang yi ge chao shi de shi jian , zhe yang lian jie shi bai de shi hou jiu bu hui “ dong jie ” cheng xu 。 <?php $cfgServer ="your.news.host"; $cfgPort =119; $cfgTimeOut =10; // open asocket if(!$cfgTimeOut) // without timeout $usenet_handle=fsockopen($cfgServer,$cfgPort); else // with timeout $usenet_handle=fsockopen($cfgServer,$cfgPort, &$errno, &$errstr,$cfgTimeOut); if(!$usenet_handle) { echo"Connexionfailed\n"; exit(); } else { echo"Connected\n"; $tmp=fgets($usenet_handle,1024); } ?> yu fu wu qi jiao hu xian zai wo men yi jing lian jie shang fu wu qi le , er qie neng gou tong guo xian qian da kai de socket lian jie yu fu wu qi jin xing jiao hu 。 rang wo men dui fu wu qi shuo “ wo men yao cong mou yi xin wen fen zu zhong huo qu dao zui xin de 10 pian wen zhang ”。RFC977 ding yi le ru he xuan ze zheng que de xin wen fen zu de ming ling , ru xia : GROUPggg bi xu de shen shu ggg shi ni jiang yao xuan ze de xin wen fen zu de ming zi , bi ru net.news。 shi yong list ming ling ni ke yi huo qu dao yi zu you xiao de xin wen lie biao 。 cheng gong xuan ze xiang ying hui fan hui zu zhong shou yi liang pian xin wen de xin wen hao yi ji dui cun dang xin wen hao gu ji 。 bi ru chrome:~$ telnetmy.news.host 119 Trying aa.bb.cc.dd... Connected tomy.news.host. Escape character is'^]'. 200 my.news.hostInterNetNews NNRP server INN 2.2.2 13-Dec-1999 ready (posting ok). GROUP alt.test 211 232 222996 223235alt.test quit 205 . zai jie shou dao ming ling “GROUP alt.test”, xin wen fu wu qi fan hui le “211232 222996 223235 alt.test”。 qi zhong 211 shi RFC biao shi ma ( jian dan de jie shi shuo ming ling yi jing cheng gong de zhi xing — cha kan RFC ni ke yi huo qu geng jia xiang xi de zi liao ), fan hui xin xi shuo ming qi zhong you 232 pian wen zhang , qi zhong zui jiu de xin wen de suo yin hao shi 222996, er zui xin de xin wen suo yin hao shi 223235。 xian zai rang wo men ji suan xia :222996+232 bing bu deng yu 232235。 zhe diu shi de wen zhang huo zhe cong zhe fu wu qi yi chu chu qu le , huo zhe bei ta de zuo zhe qu xiao le ( shi de , zhe shi ke neng de , ye shi hen rong yi shi xian de ), huo zhe shi shan chu le 。 xiao xin qi jian , zai xuan ze xin wen fen zu zhi qian , fu wu qi ke neng xu yao ren zheng , dang ran zhe shi you fu wu qi shi fou gong kai huo zhe si you lai jue ding de 。 yi ban shi yuan xu ren he ren huo qu xin wen , dan fa biao xin wen xu yao tong guo ren zheng 。 <?php //$cfgUser = "xxxxxx"; //$cfgPasswd = "yyyyyy"; $cfgNewsGroup ="alt.php"; // identification required on private server if($cfgUser) { fputs($usenet_handle,"AUTHINFO USER".$cfgUser."\n"); $tmp=fgets($usenet_handle,1024); fputs($usenet_handle,"AUTHINFOPASS".$cfgPasswd."\n"); $tmp=fgets($usenet_handle,1024); // check error if($tmp!="281Ok\r\n") { echo"502Authentication error\n"; exit(); } } // select newsgroup fputs($usenet_handle,"GROUP ".$cfgNewsGroup."\n"); $tmp=fgets($usenet_handle,1024); if($tmp=="480 Authentication required for command\r\n") { echo"$tmp\n"; exit(); } $info=split(" ",$tmp); $first=$info[2]; $last=$info[3]; print"First : $first\n"; print"Last : $last\n"; ?> huo qu yi xie wen zhang xian zai wo men yi jing you zui xin wen zhang de A suo yin hao , na jiu neng hen rong yi de huo qu zui xin de shi pian wen zhang 。RFC977 zhi chu shi yong ARTICLE ming ling ke yi he wen zhang de suo yin hao huo zhe xiao xi de ID yi qi shi yong 。 wei le xiao xin qi jian , zai zhe li , wen zhang de suo yin hao he xiao xi ID shi bu tong de , yin wei mei ge xin wen fu wu qi ding yi bu tong , suo yi zai bu tong de xin wen fu wu qi shang xiang tong wen zhang de suo yin hao dou hui bu yi yang de , dan shi xiao xi ID hao shi wei yi de ( bao han zai wen zhang de tou bu zhong ) <?php $cfgLimit =10; // upload last articles $boucle=$last-$cfgLimit; while ($boucle<=$last) { set_time_limit(0); fputs($usenet_handle,"ARTICLE$boucle\n"); $article=""; $tmp=fgets($usenet_handle,4096); if(substr($tmp,0,3) !="220") { echo"+----------------------+\n"; echo"Error onarticle $boucle\n"; echo"+----------------------+\n"; } else { while($tmp!=".\r\n") { $tmp=fgets($usenet_handle,4096); $article=$article.$tmp; } echo"+----------------------+\n"; echo"Article$boucle\n"; echo"+----------------------+\n"; echo"$article\n"; } $boucle++; } ?> wo men jin jin cong zhe ge fu wu qi de zhe ge fen zu shang huo qu le shi tiao zui xin de xin wen 。 ni ye ke yi shi yong HEAD ming ling lai zhi huo qu wen zhang de tou bu xin xi , huo zhe shi yong BODY ming ling lai huo qu xin wen de zheng wen 。 guan bi lian jie shi yong fclose() han shu ni jiu ke yi jie shu yu NNTP fu wu qi zhi jian de hui hua , dang ran ni ke yi xie yi ge xin de wen jian , ru xia : <?php // close connexion fclose($usenet_handle); ?> geng duo guan yu fclose() de xin xi , qing kan :http://www.php.net/manual/function.fclose.php jie lun ben wen zhong , wo men zhi shuo ming le zai que ding de qing kuang xia ru he da kai 、 shi yong he guan bi yi ge socket lian jie : lian jie shang yi ge NNTP fu wu qi ran hou cong xin wen fen zu zhong qu hui yi xie wen zhang 。 shi yong POST ming ling zai NNTP fu wu qi shang fa biao yi pian wen zhang bing bu fu duo duo shao 。 yin ci , xia yi bu jiu shi bian xie yi ge xin wen ke hu duan ( bing qu diao yi xie Netscape), ta xu yao neng hen rong yi de bao cun wen zhang , bing shi yong yi xie sou suo yin qing ( bi ru htgid,http://www.htdig.org/) lai suo yin zhe xie wen zhang , er qie yao you yi ge WEB ying yong cheng xu neng jin xing xin wen fen zu xia de guan jian zi sou suo 。 zhe li you yi ge li zi , ni ke yi fang wen [url=http://www.phpindex.com/ng/]http://www.phpindex.com/ng/[/url] qu xia zai 。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
玉美人_珠联璧合
清纯美女米卡
清新靓丽的早晨
玲子的自信与性感
痞子的甘南日记
疑是银河落九天
雪域坝上四——纯美色
冬日恋歌——西城杨柳弄轻柔
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有