<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Lukas Hron</title>
    <description>The latest articles on Forem by Lukas Hron (@lukashron).</description>
    <link>https://forem.com/lukashron</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1431599%2Ffdbd7cf9-7401-4b59-ba2c-2ccdb696e4f2.jpg</url>
      <title>Forem: Lukas Hron</title>
      <link>https://forem.com/lukashron</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lukashron"/>
    <language>en</language>
    <item>
      <title>Problem with Installing ImageMagick for PHP 8.4 in Docker.</title>
      <dc:creator>Lukas Hron</dc:creator>
      <pubDate>Thu, 27 Feb 2025 16:36:35 +0000</pubDate>
      <link>https://forem.com/lukashron/problem-with-installing-imagemagick-for-php-84-in-docker-223f</link>
      <guid>https://forem.com/lukashron/problem-with-installing-imagemagick-for-php-84-in-docker-223f</guid>
      <description>&lt;p&gt;If you use the ImageMagick extension and plan to upgrade to PHP 8.3 or 8.4, you will encounter an issue with installation via PECL. Unfortunately, the PECL package is not compatible with these PHP versions, causing the installation to fail. As an alternative, you can build the source code directly from the repository, which allows you to bypass this issue and successfully configure ImageMagick.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN apt-get update &amp;amp;&amp;amp; apt-get install -y \
    imagemagick \
    libmagickwand-dev \
    &amp;amp;&amp;amp; git clone https://github.com/Imagick/imagick --depth 1 /tmp/imagick \
    &amp;amp;&amp;amp; cd /tmp/imagick \
    &amp;amp;&amp;amp; phpize &amp;amp;&amp;amp; ./configure \
    &amp;amp;&amp;amp; make \
    &amp;amp;&amp;amp; make install \
    &amp;amp;&amp;amp; apt-get clean

RUN docker-php-ext-enable imagick
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>php</category>
      <category>docker</category>
      <category>imagemagick</category>
    </item>
    <item>
      <title>Basic Protection Against Max Execution Time Limit</title>
      <dc:creator>Lukas Hron</dc:creator>
      <pubDate>Wed, 25 Sep 2024 10:57:30 +0000</pubDate>
      <link>https://forem.com/lukashron/basic-protection-against-max-execution-time-limit-ecj</link>
      <guid>https://forem.com/lukashron/basic-protection-against-max-execution-time-limit-ecj</guid>
      <description>&lt;p&gt;Anyone who has dealt with importing or exporting data has likely encountered the problem of a script running into a short execution time limit. The quickest solution often involves adjusting the PHP configuration or completely disabling the limit at the beginning of the script. However, extending the execution time significantly or disabling it altogether introduces security risks. An unstoppable background script can lead to excessive resource consumption.&lt;/p&gt;

&lt;p&gt;When processing tasks over iterations, it's possible to monitor individual passes in time and attempt to gracefully terminate execution before the time limit expires.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// initialize basic variables for further work
$maxExecutionTime = (int)ini_get('max_execution_time');
$estimateCycleTime = 0;
$startTime = microtime(true);

// For demonstration purposes, we use an "infinite" loop with a simulated task lasting 10 seconds
while (true) {
   sleep(10);

   // Calculate the current runtime
   $currentRunTime = microtime(true) - $startTime;

   // Termination can be done either with a fixed constant
   // or by measuring the time of one pass and trying to use
   // the longest possible segment of the runtime
   // limit (has its problem).
   if ($estimateCycleTime === 0) {
       $estimateCycleTime = $currentRunTime;
   }

   // Check if the iteration stop time is approaching.
   // Subtract the time of one pass, which likely won't fit
   // within the window. 
   if (($maxExecutionTime - $estimateCycleTime) &amp;lt; $currentRunTime) {
       echo 'Time is end';
       break;
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Early termination based on the calculation of one pass is suitable for cases where there are a large number of passes that need to be processed in as few new executions as possible, and each operation in one pass is similarly time-consuming. If individual passes differ in their time requirements, a coefficient must be added to the pass time. Another option is to use a predefined time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$beforeEndTime = 1;

if (($maxExecutionTime - $beforeEndTime) &amp;lt; $currentRunTime) {
    echo 'Time is end';
    break;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the script continues after iteration, such as closing connections to API endpoints, closing files, or performing other operations, it's essential to remember to add this time.&lt;/p&gt;

</description>
      <category>php</category>
    </item>
    <item>
      <title>Convert UTF8 to Windows 1250</title>
      <dc:creator>Lukas Hron</dc:creator>
      <pubDate>Thu, 01 Aug 2024 14:04:14 +0000</pubDate>
      <link>https://forem.com/lukashron/convert-utf8-to-windows-1250-2o64</link>
      <guid>https://forem.com/lukashron/convert-utf8-to-windows-1250-2o64</guid>
      <description>&lt;p&gt;When working with different encodings, it may be necessary to convert text from one format to another. If you need to convert text from UTF-8 encoding to Windows-1250 using PHP, the script below can help you. This script performs the conversion and offers the output text for download.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fileName = 'encoded.txt';
$inputText = 'Example text';

setlocale(LC_CTYPE, 'cs_CZ');
$output = iconv('UTF-8', 'Windows-1250//TRANSLIT', $inputText);

ob_clean();
header("Expires: Mon, 1 Apr 1970 05:00:00 GMT");
header(sprintf("Last-Modified: %s GMT", gmdate("D,d M YH:i:s")));
header("Pragma: no-cache");
header(sprintf("Content-type: application/octet-stream; charset=windows-1250; name=%s", $fileName));
header(sprintf("Content-Disposition: attachment; filename=%s", $fileName));
header(sprintf("Content-Length: %s", strlen($output)));
header("Content-Transfer-Encoding: binary");
header("Content-Description: Export dat");
echo $output;
exit;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tool makes it easier to work with texts in different encodings, especially if you're dealing with Czech characters or other Central European languages. I hope you find it useful!&lt;/p&gt;

</description>
      <category>php</category>
      <category>utf8</category>
      <category>windows1250</category>
    </item>
    <item>
      <title>Installing NPM with Docker</title>
      <dc:creator>Lukas Hron</dc:creator>
      <pubDate>Wed, 17 Apr 2024 14:24:58 +0000</pubDate>
      <link>https://forem.com/lukashron/installing-npm-with-docker-35ib</link>
      <guid>https://forem.com/lukashron/installing-npm-with-docker-35ib</guid>
      <description>&lt;p&gt;How to install NPM into my custom Docker container? We will show three basic ways in DockerFile.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First and simple way&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM debian:11-slim
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y wget gnupg g++ apt-utils curl git &amp;amp;&amp;amp; apt-get clean

######################

RUN apt-get update &amp;amp;&amp;amp; apt-get install -y npm &amp;amp;&amp;amp; apt-get clean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Installing with NVM tool&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM debian:11-slim
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y wget gnupg g++ apt-utils curl git &amp;amp;&amp;amp; apt-get clean

######################

ENV NODE_VERSION 20.12.2
ENV NVM_DIR /usr/local/nvm

RUN mkdir -p $NVM_DIR

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

RUN . "${NVM_DIR}/nvm.sh" \
    &amp;amp;&amp;amp; nvm install $NODE_VERSION \
    &amp;amp;&amp;amp; nvm alias default $NODE_VERSION \
    &amp;amp;&amp;amp; nvm use $NODE_VERSION

ENV PATH="${NVM_DIR}/versions/node/v${NODE_VERSION}/bin:${PATH}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Installing from Debian Nodesource resources&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM debian:11-slim
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y wget gnupg g++ apt-utils curl git &amp;amp;&amp;amp; apt-get clean

######################

RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \
    &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp; apt-get install -y nodejs \
    &amp;amp;&amp;amp; apt-get clean

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>npm</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
