PHP Unknown: [UNAVAILABLE] FETCH Server error while fetching messages (errflg=2) - php

When running the following command once:
<?php
$imap_structure = imap_fetchstructure($mail_connection, $email_number);
?>
I get the following error message:
Unknown: [UNAVAILABLE] FETCH Server error while fetching messages (errflg=2)
To confirm that PHP's imap_fetchstructure function was causing the error I used die(); after each imap_* function from the top of the function moving down until I started receiving the error again. Here is a list of things I've checked:
Each email message is successfully retrieved from Yahoo and added to the database as if nothing went wrong; the process is dependent on getting the structure of this email so on that alone I'm at a loss as to how something can work while also throwing an error.
This literally just started happening randomly after having already tested my mail script on a few hundred emails (not all at once, in much smaller batches).
Only happens with PHP's imap_fetchstructure function; when looped (e.g. for ten emails) the error will occur for each iteration.
Only occurring for the Yahoo mail server, other servers aren't triggering this error with the exact same code.
The custom error handler fails to return the line number (though I know where the error is occurring.
I tried suppressing the error by using #imap_fetchstructure() though the error was still being reported.
I tried sticking the code in to a try {} / catch (exception $e) {} though, again, the error was still being reported.
I restarted my server and pulled a different IP just because that has worked in stupider situations though no dice.
[Edit] The issue stopped little less than an hour after it started.
I've come across a few folks who have reported such as at Mozillazine:
I have recently started getting this "[UNAVAILABLE] UID FETCH Server error while fetching messages" too with my Yahoo account.
Their next post:
So today, without doing anything differently, the problem solved itself. That seems to say it was on Yahoo's end but it's still odd that while it was happening in Thunderbird it wasn't happening in other email clients.
Beyond literally hard-coding my custom error handler to ignore this error how do I suppress or code my system to better handle this situation?

Had a similar issue (not with programming) with Yahoo (in Thunderbird) and found this answer. Don't know if it would apply to your situation:
You can try to reduce the "Maximum number of connections to cache" for any of the affected Yahoo account(s). The option is in Account Settings -Server Settings - Advanced.
Mine is set to a value of 3 (was 5), which works for Yahoo.

Related

Connection to Artemis via Stomp breaks when trying to read big messages using SSL

My code is fairly simple. I'm using the library over at https://github.com/stomp-php/stomp-php, and try to read messages from an Artemis queue. It's just a simple $stomp->read();.
Expected behaviour:
I get one message from the queue, or get told that there are no messages in the queue
What is happening:
The read method throws an exception (see below)
When we don't connect using SSL, with a basic TCP connection, without a certificate, everything works perfectly fine. It happens only when we connect with the ssl scheme, the SSL port, with the certificate.
The exception is: Was not possible to read data from stream., thrown in [stomp-php directory]/src/Network/Connection.php line 473.
Here is the context for the stream connection:
ssl:
peer_name: '[censored]'
cafile: '[censored certificate path].cer'
The certificate file exists and is read correctly (since when I change the path there's an exception thrown even before trying to send a message). The peer name is also correct, since another one triggers another error telling me that the peer name is incorrect.
My test is simple: I have a file that sends the messages, and a file that reads them. The sending always works when I don't subscribe to the queue. The reading is kinda messy.
New information: the reading seems to work when I remove 5 specific messages from the sending. That means if I send one of those 5, the reading throws the exception. If there are only the other messages but none of these 5, the reading works great. I would assume that the messages are in cause, but again, when I'm not connecting using SSL, everything works correctly.
New information again: every message that I have to not send in order to not have an error has a big amount of lines. I tried to send one of them again and remove every node but one from its content (XML): it worked correctly. So I tried with ~900 nodes: error. ~200 nodes: error. ~130 nodes: sometimes error. ~80 nodes: working.
SSL has troubles with large messages?
New information again again: I tried var_dumping the result of the fread call in the library. When the error occurs, the result is an empty string (''). From what I read in the doc, fread returns false on failure, and empty string on timeout. It would make sense with the "New information again" bloc, in which we discovered that large messages are causing the problem.
I tried stream_set_timeout() with 60 seconds, I tried to send a heartbeat manually, I tried setting it with the lib, I tried changing the timeouts with the lib and I tried increasing the maxReadBytes. Nothing worked so far. Still the same behaviour.
Fixed by reverting stomp-php library to version 4.3.1 :(

What does "i360: Error in global initialization" mean in PHP?

A PHP software I wrote has been working fine for years suddenly throws this error: i360: Error in global initialization
This error is being thrown from the callback function register_shutdown_function('my_shutdown');
The callback function is just something this:
function my_shutdown ()
{
chdir(getcwd());
$e = error_get_last();
if ($e)
trigger_error($e['message'].' on '.$e['file'].' ('.$e['line'].')', E_USER_ERROR);
}
The full error message that trigger_error throws is:
i360: Error in global initialization 1 on Unknown (0).
It doesn't give much clue. Any ideas what could be causing it?
Update 1:
If I comment out the entire my_shutdown() function, the script works fine but I am still intrigue as to why this error happened just today after years of working fine.
Update 2:
Tentative info: this appears to be related to Imunify360, a security software for web servers (which my host uses that I'm not aware of or have control over). Investigation ongoing.
This issue is caused by Imunify360 because of a recent update to include a feature called "Proactive Defense":
https://www.imunify360.com/blog/meet-imunify360-with-proactive-defense-the-sophisticated-protection-against-any-kind-of-malware-all-in-one-nice-package
To fix this you need to have your host disable the extension over all PHP versions:
sed -i "s/extension=i360.so/;extension=i360.so/g" /opt/alt/php*/etc/php.ini
That should fix the problem for the time being.
This error happened just today. It disappears when I delete my cron jobs on Hawk Host cpanel.
This error was confirmed to be coming from Imunify360 (a security software for web servers). At the time of this writing, the issue was already fixed on their end. I presume an update was applied to servers using it so if you're still getting this error, contact your host.

CakePHP - making sure CakeEmail error not stopping the script and continuing with the rest

I'm using CakeEmail to send out email campaigns using our own SMTP server.
During a campaign sending, I noticed that one email (in ~1000) failed to be sent because the address doesn't exist or malfunctioned (or being blocked by anti-spam).
However, instead of continuing with the rest, the script (which is called by a cron tab through a shell command) stopped with an error reported in the command line (I think the error code was 510 or so). I had to run the command manually to make sure the rest got sent.
The email sending code is quite ordinary:
// ...
$email->from($settings['from'])
->to($to)
->subject($settings['subject'])
->replyTo($settings['reply_to'])
->returnPath($settings['return_path']);
return $email->send($body);
// ...
Now, how do I make sure the script won't stop and keep going despite one or many emails are failed to be sent?
how do I make sure the script won't stop and keep going
Depends on the kind of error. Read this and report the exact error next time.
I assume it's an exception: Just use exception handling, try / catch to catch them, log the error if needed and continue.

Swiftmailer crashes without php error

I have a web app that allows the user to upload a pdf and it will then email it to us via swiftmailer. With some pdfs, the process fails.
I can verify that it crashes the php script, yet returns no php error. There's a 500 error from the server, but normally if there's a 500 error, php has a log of what the error was.
I have also verified that it crashes at the
$mailer->send($message);
line
Oddly, only some pdfs crash it, and those same pdfs work fine on the development server with identical code.
What could be causing php to crash without an error message?
After running several tests, I found that error logging was happening some of the time, but not others. I didn't figure out why that was so, however, I tried renaming the php-errors.log file so php would start with a new, fresh log file, and now errors are getting logged properly. I don't know why that worked, but I'll take it.
FYI, I've run into two things that can cause a PHP crash without an error message:
Script timeouts - A timeout may prevent an error message from being returned; in my particular case the script was waiting for an SMTP response when the timeout happened, which may have been why I didn't get a timeout message. Try changing your max_execution_time value in php.ini to 300 (5 minutes) and see if you can get an actual error message.
Folder permissions - I've encountered a case where insufficient folder permissions resulted in the script just halting without providing an error.
In the case of 2, I wrapped a try/catch clause around the line that was causing the halt, and I finally got an Exception to show up explaining about the permissions problem. That may be worth trying as a general response to silent crashes.

PHP script throwing internal server error 500, fixed when turning on display_errors

I came across an issue today, that my PHP script would send a server error 500 upon finishing (on apache). The code was something like:
//many stuff here that work
echo "It reached here";
exit;
and I was always reaching the point before the exit; command. Doing a google search, I came across this post, which suggested turning on display_errors. I did it and the 500 error went away.
So I wanted to ask, does anyone have an explanation on why this happens? This SO post describes a similar case, but there are no explanations.
As always, thanks in advance
It's pretty likely you get a 500 status code as well, but because PHP echoes something to the browser apache won't jump in and display it's standard status 500 error page.
You would need to verify the actual status code to verify that you won't still get a 500 error.
In case of a fatal error, PHP normally sends a 500 status code. As often the process has failed at that time (hence causing the fatal) and sometime no output is generated since then, the webserver jumps in and gives the user the standard 500-internal-server-error-page.
It appears that the code generated a parse error inside an eval() function in a loop. This kind of error does not break code execution but does produce a 500 error

Categories