When PHP uses fsockopen, \ r \ n and \ n terminator in fwrite cause smtp.qq.com response problem

Source: Internet
Author: User

<?php$t= time (); $sk = Fsockopen (' tcp://smtp.qq.com ', $errno, $ERRSTR, 5); echo "Sockect OK:". (Time ()-$t). " \ n ";" if (! Is_resource ($sk)) exit (' Connect error: '. $errno. ") ". $errstr);//set to block mode stream_set_blocking  ($sk, 1);//Get Initial link information var_dump (fgets ($SK, 512));//Set Read timeout stream_set_ Timeout ($sk, 3), Var_dump (Stream_get_meta_data ($sk)), fwrite ($sk, "EHLO qidizi.com\n");//This will cause a timeout, Personal judgment should be QQ in waiting for a line of input terminator, but \ n is not, should be \ r \ n is, will be stuck here does not output hint, this problem, in the previous version, and the current test, 163.com did not find this problem//fwrite ($sk, "EHLO Qidizi.com\r\n ");//the correct line terminator \ r \ n, will immediately get a response Var_dump (fgets ($SK, 512). ': '. ( Time ()-$t));//The above will not timeout echo "4:". (Time ()-$t). " \n<br/> "; Var_dump (Stream_get_meta_data ($sk)); fclose ($SK);

Test code



May QQ server in recent changes in the change, remember the previous can use \ n to do as a line of Terminator, that is, a fwrite ($sk, "kkk\n") to get a response, Fgets can immediately succeed, test a bit 163,\n is no problem, recently found that QQ \ N has a problem, causing no response, fgets because the buffer does not have content that causes an exception until the read time-out. But QQ changed to \ r \ n Normal.


So smtp.qq.com, and smtp.exmail.qq.com have this problem.

I started to think that some people were talking about becoming SSL. It's not. Now the 25 port is still working.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.