Php

sandbox.smtp.mailtrap.io port 25 isn't available anymore

I can’t connect to port 25 anymore. I noticed it in a Laravel application but the issue exists for everyone.

nc -vvv sandbox.smtp.mailtrap.io 25

just doesn’t connect.

It’s been an issue for a few weeks now.

To fix it just change the port 25 to 2525 (this one doesn’t require TLS).

Composer install - ignore php version constrains

Solution

Just run this:

composer install --ignore-platform-req=php

Issue

I often have an issue when after upgrading PHP to a newer versions I can’t do composer install anymore because one or more libraries haven’t updated their require.php section to support newer version of the language.

Moreover, even if you manage to install new versions of those libs you still may have other projects on your machine that require older version of php (my case).

PHP: visual charset detection of a string

Sometimes in mb_convert_encoding($str, 'UTF-8', 'auto') that latest auto argument won’t work.

To find what charset the string is using you can get all possible charsets, convert your $str into that charset and print it:

foreach(mb_list_encodings() as $charset) {
    echo mb_convert_encoding($str, 'UTF-8', $charset) . ' ----- ' . $chr . "\n";                                                                                                2              }
}

This code may not work for some charsets returned by mb_list_encodings(). You can ignore some of them like this:

foreach(mb_list_encodings() as $charset) {
    if (in_array($chr, ['pass', 'wchar', 'byte2be', 'byte2le', 'byte4be', 'byte4le', 'BASE64', 'UUENCODE', 'HTML-ENTITIES', 'Quoted-Printable', '7bit', '8bit'])) {
        continue;
    }
    echo mb_convert_encoding($str, 'UTF-8', $charset) . ' ----- ' . $chr . "\n";                                                                                                2              }
}

Of course it’s only applicable if you know that $str will always be in the charset you found.

PHPNotifier - task scheduler

Hi, Couple of days ago, working on my full-time project, I noticed we have a huge crontab file. We have a lot of different scripts that checks status of different records in our database or status of users or status of emails that we sent or, or, or…

A lot of our classes have different flags (“checked”, “sent”, “approved”, etc…) and its something that really hard to manage.

Crontab is very useful tool but incase you use for things it was developed.