<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ruslan&#39;s Tech Blog</title>
    <link>https://blog.bekenev.net/tags/php.html</link>
    <description>Software development related stuff</description>
    <language>en-us</language>
    <lastBuildDate>Tue, 12 Dec 2023 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.bekenev.net/tags/php/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>sandbox.smtp.mailtrap.io port 25 isn&#39;t available anymore</title>
      <link>https://blog.bekenev.net/2023/12/12/mailtrap-port-25-doesnt-work-anymore.html</link>
      <pubDate>Tue, 12 Dec 2023 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2023/12/12/mailtrap-port-25-doesnt-work-anymore.html</guid>
      <description>&lt;p&gt;I can&amp;rsquo;t connect to port 25 anymore.&#xA;I noticed it in a Laravel application but the issue exists for everyone.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;nc -vvv sandbox.smtp.mailtrap.io &lt;span style=&#34;color:#ae81ff&#34;&gt;25&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;just doesn&amp;rsquo;t connect.&lt;/p&gt;&#xA;&lt;p&gt;It&amp;rsquo;s been an issue for a few weeks now.&lt;/p&gt;&#xA;&lt;p&gt;To fix it just change the port 25 to 2525 (this one doesn&amp;rsquo;t require TLS).&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>Composer install - ignore php version constrains</title>
      <link>https://blog.bekenev.net/2023/12/11/php-composer-ignore-php-version.html</link>
      <pubDate>Mon, 11 Dec 2023 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2023/12/11/php-composer-ignore-php-version.html</guid>
      <description>&lt;h2 id=&#34;solution&#34;&gt;Solution&lt;/h2&gt;&#xA;&lt;p&gt;Just run this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;composer install --ignore-platform-req&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;php&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;issue&#34;&gt;Issue&lt;/h2&gt;&#xA;&lt;p&gt;I often have an issue when after upgrading PHP to a newer versions I can&amp;rsquo;t do &lt;code&gt;composer install&lt;/code&gt;&#xA;anymore because one or more libraries haven&amp;rsquo;t updated their &lt;code&gt;require.php&lt;/code&gt; section to support&#xA;newer version of the language.&lt;/p&gt;&#xA;&lt;p&gt;Moreover, even if you manage to install new versions of those libs you still may have other&#xA;projects on your machine that require older version of php (my case).&lt;/p&gt;&#xA;&lt;p&gt;I also prefer to have programming languages installed on my machine directly without any docker stuff that would potentially solve this issue. Also I&amp;rsquo;m not aware of any solutions like NVM or RVM for PHP.&lt;/p&gt;&#xA;&lt;br&gt;&#xA;[Found this info in this post](https://php.watch/articles/composer-ignore-platform-req). Check it out for some more tips.&#xA;</description>
    </item>
    <item>
      <title>PHP: visual charset detection of a string</title>
      <link>https://blog.bekenev.net/2020/11/25/visual-detection-of-charset-in-php.html</link>
      <pubDate>Wed, 25 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2020/11/25/visual-detection-of-charset-in-php.html</guid>
      <description>&lt;p&gt;Sometimes in &lt;code&gt;mb_convert_encoding($str, &#39;UTF-8&#39;, &#39;auto&#39;)&lt;/code&gt; that latest &lt;code&gt;auto&lt;/code&gt; argument won&amp;rsquo;t work.&lt;/p&gt;&#xA;&lt;p&gt;To find what charset the string is using you can get all possible charsets, convert your &lt;code&gt;$str&lt;/code&gt; into that charset and print it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-php&#34; data-lang=&#34;php&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;foreach&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;mb_list_encodings&lt;/span&gt;() &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; $charset) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;mb_convert_encoding&lt;/span&gt;($str, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;UTF-8&amp;#39;&lt;/span&gt;, $charset) &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39; ----- &amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; $chr &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;;                                                                                                &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;              }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This code may not work for some charsets returned by &lt;code&gt;mb_list_encodings()&lt;/code&gt;. You can ignore some of them like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-php&#34; data-lang=&#34;php&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;foreach&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;mb_list_encodings&lt;/span&gt;() &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; $charset) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#a6e22e&#34;&gt;in_array&lt;/span&gt;($chr, [&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;pass&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;wchar&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;byte2be&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;byte2le&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;byte4be&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;byte4le&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;BASE64&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;UUENCODE&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;HTML-ENTITIES&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Quoted-Printable&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;7bit&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;8bit&amp;#39;&lt;/span&gt;])) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;continue&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;mb_convert_encoding&lt;/span&gt;($str, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;UTF-8&amp;#39;&lt;/span&gt;, $charset) &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39; ----- &amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; $chr &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;;                                                                                                &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;              }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Of course it&amp;rsquo;s only applicable if you know that &lt;code&gt;$str&lt;/code&gt; will always be in the charset you found.&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>PHPNotifier - task scheduler</title>
      <link>https://blog.bekenev.net/2016/03/27/phpnotifier.html</link>
      <pubDate>Sun, 27 Mar 2016 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2016/03/27/phpnotifier.html</guid>
      <description>&lt;p&gt;Hi,&#xA;Couple of days ago, working on my full-time project, I noticed we have a huge crontab file.&#xA;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…&lt;/p&gt;&#xA;&lt;p&gt;A lot of our classes have different flags (“checked”, “sent”, “approved”, etc…) and its something that really hard to manage.&lt;/p&gt;&#xA;&lt;p&gt;Crontab is very useful tool but incase you use for things it was developed.&lt;/p&gt;&#xA;&lt;p&gt;So, we were needed a task scheduler. Since we use PHP in our project it would be great to have it as packagist package but… I didn’t find anything that fit our needs.&lt;/p&gt;&#xA;&lt;p&gt;So, today I finished my work on such library and I hope it will be useful not only for me and our team.&lt;/p&gt;&#xA;&lt;p&gt;Meet &lt;a href=&#34;https://github.com/KryDos/PHPNotifier&#34;&gt;PHPNotifier already&lt;/a&gt; published in packagist.&#xA;This library allows you to schedule a task to the exact time or after some time.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-php?start_inline=1&#34; data-lang=&#34;php?start_inline=1&#34;&gt;&#xA;use \PHPNotifier\PHPNotifier;&#xA;$scheduler = new PHPNotifier(PHPNotifier::FILE_METHOD, &amp;#39;/absolute/path/to/db.file&amp;#39;);&#xA;&#xA;$scheduler-&amp;gt;scheduleTaskIn(10, &amp;#39;echo&amp;#39;, [ #execute &amp;#34;echo&amp;#34; command&#xA;&#x9;&amp;#39;Hello world!&amp;#39; # with &amp;#34;Hello world!&amp;#34; argument&#xA;&#x9;&amp;#39;&amp;gt;&amp;#39; # and redirect output&#xA;&#x9;&amp;#39;any_file&amp;#39; # to any_file&#xA;]);&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;br/&gt;&#xA;&lt;p&gt;This code will schedule task that will be running in 10 seconds. And its awesome. Now, in our project, we have internal API calls (HTTP), that are triggering different tasks. PHPNotifier is sending curl requests to the API and it works great.&lt;/p&gt;&#xA;&lt;p&gt;Checkout &lt;a href=&#34;https://github.com/KryDos/PHPNotifier&#34;&gt;GitHub page&lt;/a&gt; of this library. You can find more documentation there. It would be great if you can suggest how to improve it or even send a pull request.&lt;/p&gt;&#xA;</description>
    </item>
  </channel>
</rss>
