php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76663 fwrite(): send of X bytes failed with errno=32 Broken pipe
Submitted: 2018-07-25 15:37 UTC Modified: 2018-07-25 19:10 UTC
From: standus at post dot cz Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.31 OS: CentOS, linux, windows
Private report: No CVE-ID: None
 [2018-07-25 15:37 UTC] standus at post dot cz
Description:
------------
I have code for testing huge of emails existence.
Using functions:
getmxrr($domain, $hosts, $mxweights);
gethostbyname($host);

After 1 or 2 hours cron runnig it will fail with errors:
fwrite(): send of 38 bytes failed with errno=32 Broken pipe
fwrite(): send of 29 bytes failed with errno=104 Connection reset by peer

A am using simple php class which dooing this functionality:
https://github.com/semplon/php-smtp-email-validation

Test script:
---------------
// include SMTP Email Validation Class
require_once('smtp_validateEmail.class.php');
// the email to validate
$emails = array('user@example.com', 'user2@example.com', ...); //or foreach from DB storage
// an optional sender
$sender = 'user@yourdomain.com';
// instantiate the class
$SMTP_Validator = new SMTP_validateEmail();
// turn on debugging if you want to view the SMTP transaction
$SMTP_Validator->debug = true;
// do the validation
$results = $SMTP_Validator->validate($emails, $sender);
// view results
foreach($results as $email=>$result) {
	// send email? 
  if ($result) {
    //mail($email, 'Confirm Email', 'Please reply to this email to confirm', 'From:'.$sender."\r\n"); // send email
  } else {
    echo 'The email address '. $email.' is not valid';
  }
}

Expected result:
----------------
no errors


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-25 15:38 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-07-25 15:38 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

https://github.com/semplon/php-smtp-email-validation/issues
 [2018-07-25 15:38 UTC] standus at post dot cz
-Status: Not a bug +Status: Open -Operating System: windows +Operating System: CentOS, linux, windows
 [2018-07-25 15:38 UTC] standus at post dot cz
Afted that some PHP function has some problem with DNS resolver.
 [2018-07-25 15:45 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-07-25 15:45 UTC] requinix@php.net
The only place in that code with an fwrite() is where it tries to write to a socket. Sockets break. It happens.
 [2018-07-25 16:22 UTC] standus at post dot cz
Other way is that in documentation for fwrite is return status if this function will fail but its not happen.
 [2018-07-25 16:25 UTC] standus at post dot cz
By me when some function is impossible catch it or prevent problem with @ prefix its big problem which broken long running script. I except when fwrite function return false when some uncatchable problem will happen.
 [2018-07-25 16:41 UTC] requinix@php.net
The code you linked, which hasn't received any updates in more than four years, and was clearly written for PHP 4, does not check the return value of fwrite at all.

But verifying an email account with the SMTP server is not even reliable in the first place. Require the address be entered twice by the user, validate the email address syntax is correct, and send a confirmation email with a link to your site that the user clicks so you know they received it.
 [2018-07-25 16:50 UTC] standus at post dot cz
This problem happened to me every day with any long time running script.
And it has not solution. Thats why I wrote this bug because I mean it must be solved in PHP function code.
 [2018-07-25 16:54 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.
 [2018-07-25 17:24 UTC] standus at post dot cz
And what about my arguments:
1.
in Documentation is not anything about "Notice message" when it will fail. There is only return false on fail. ???
2.
Its impossible catch it ?
 [2018-07-25 17:26 UTC] standus at post dot cz
I tried already many times and many channels and nobody knows answer. Nobody knows solution because it does not exists !
 [2018-07-25 17:48 UTC] spam2 at rhsoft dot net
don't try to verify mail by bother the MX - period

you can't handle grexlisting, tarpits and a ton of other spamfiter measurements only a proper smtp server which retries repeatly and handles temporary errors as defined in the according rfcs

the whole point on the smtp server side is to kill spam scripts like yours - i just let you wait 15 seconds, then respond with 450 and expect that you come with the same ip not sooner than 5 minutes or you have to wait 10 minutes


as Mailadmin in clear words:let the world in peace with your crap script
 [2018-07-25 17:57 UTC] requinix@php.net
>in Documentation is not anything about "Notice message" when it will fail. There is only return false on fail. ???
fwrite works with PHP streams, which can be files or sockets or other resources. It is not possible to document every possible way that this function could present an error. E_NOTICE happens because it is a socket, and the write operation on the socket had a problem.

I do not know if it is possible to get the errno from a failed fwrite on a socket. Regardless, you should *not* use @ because having those error messages is *good* because they tell you of a real problem. The code should be checking the return value from fwrite - not just for an error but in case the write operation did not transmit all the data expected, which could cause the remote server to abort the connection, which could be the source of your problem.

>Its impossible catch it ?
You can "catch" notices and other error messages with set_error_handler().

>Nobody knows solution because it does not exists !
Just because nobody knows the solution does not mean there is no solution at all.

Except there is a solution: the code you are using is old and flawed, but you should not be using this method to verify email addresses at all so it does not matter.
 [2018-07-25 18:14 UTC] standus at post dot cz
I dont need answer for architecture or solution, I reported problem with fwrite function.
 [2018-07-25 18:19 UTC] standus at post dot cz
I already tried try catch but its the same, not solved. It will still produce Notice.
 [2018-07-25 18:54 UTC] spam2 at rhsoft dot net
you need to understand that there is no problem with fwrite
it is just the messenger

you can't treat others mailservers like you do - frankly you can't even use unconditional sender-verify that way unless you want get blacklisted

stop to argue - what you are doing is utterly bullshit and you get what you asked for - for normal usage after a successful fopen that never does happen and when it happens it points out a serious problem you want to know about

would you mind to tell the ip of your machine so that it can be added to blacklists?
 [2018-07-25 19:10 UTC] standus at post dot cz
I understand what you talk about, but I am not sending emails I am just verify existence of email address. Its different think.
No other way exists to verify email address than ask smtp server.
 [2018-07-25 19:39 UTC] spam2 at rhsoft dot net
I know that you only try to verify it and I did that 20 years ago too but you can't do it in 2018 - cope with the fact

when you have 50 of our users in your list you are blocked for two hours and you can't know unless you are extremely careful, our MX hosts hundredts of domains and doing it in batch would block you within seconds because that's not how a reasonable MTA acts 

from the view of a mail operator you behave like a Spammer and you are threatened as such which explains the errors you see

there is no single way you can verify RELIEABLE that an email exists, even not with bounce management based on maillogs because these days crap providers like office365 even accept the whole message, respond with 2xx and later send a backscatter to the often forged innocent sender that the account does not exist


just forget what you are trying to do - it is not possible and in doubt it creates more harm than good
 [2018-07-26 03:54 UTC] a at b dot c dot de
"No other way exists to verify email address than ask smtp server."

The only way to reliably verify an email address is to send an email to the address asking the recipient to reply (maybe include a link that they can use to confirm they received it). You might get back an error claiming that the address doesn't exist. But not getting an error doesn't prove the address does exist.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sat Nov 17 02:01:25 2018 UTC