<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joe Cohen on Medium]]></title>
        <description><![CDATA[Stories by Joe Cohen on Medium]]></description>
        <link>https://medium.com/@joecohens?source=rss-cbcb38303231------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u6HXiS5O06zpZfprzBtcBA.jpeg</url>
            <title>Stories by Joe Cohen on Medium</title>
            <link>https://medium.com/@joecohens?source=rss-cbcb38303231------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 07:30:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joecohens/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Improving Glide image server response by 6x with PHP-PM and zero code changes]]></title>
            <link>https://medium.com/@joecohens/improving-glide-image-server-response-by-6x-with-php-ppm-and-zero-code-changes-180fd333cc09?source=rss-cbcb38303231------2</link>
            <guid isPermaLink="false">https://medium.com/p/180fd333cc09</guid>
            <category><![CDATA[glide]]></category>
            <category><![CDATA[php-ppm]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Joe Cohen]]></dc:creator>
            <pubDate>Tue, 09 Jan 2018 18:41:52 GMT</pubDate>
            <atom:updated>2018-01-09T18:54:12.865Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/thephpleague/glide"><strong>The PHP League Glide</strong></a> project it’s an “easy on-demand image manipulation library written in PHP”. It uses an HTTP API to manipulate images on the fly similar of what services like services like <a href="http://www.imgix.com/"><strong>Imgix</strong></a> and <a href="http://cloudinary.com/"><strong>Cloudinary</strong></a>, but self hosted.</p><p>We’ve use this project many times as a standalone library or as a self hosted service and it’s really great! However when used on high traffic projects or scaling the service into many servers it can be tricky and very slow since it uses PHP to process and serve static files.</p><p>Last week we’ve experimented switching one of our images services from <strong>PHP-FPM</strong> to <a href="https://github.com/php-pm/php-pm"><strong>PHP-PM</strong></a> written in <a href="https://lumen.laravel.com/"><strong>Laravel Lumen</strong></a> and using <a href="https://github.com/thephpleague/glide"><strong>Glide</strong></a>.</p><p>The cool thing it’s that we didn’t change a line code! <em>(only server config)</em></p><p><a href="https://github.com/php-pm/php-pm"><strong>PHP-PM</strong></a> is a new PHP process manager using <a href="https://reactphp.org/"><strong>ReactPHP</strong></a> (an “Event-driven, non-blocking I/O with PHP”) underneath, that focuses in making modern PHP applications fast by spawning several PHP instances as workers with your application bootstrapped and stored in memory prepared for every incoming request, and the results are very impressive!</p><p>The tests below were made on two Linode’s with 4GB on RAM and 2 CPU’s, both with php 7.2 but one running <strong>PHP-FPM</strong> and the other <strong>PHP-PM</strong>.</p><p>We ran ab -c 10 -n 1000 <a href="http://path/">http://path</a> on each server and here are the results:</p><p><strong>Server running php-fpm with php-7.2 and opcache</strong></p><pre>Document Path:          /images/img_growth.png<br>Document Length:        35908 bytes</pre><pre>Concurrency Level:      10<br>Time taken for tests:   133.043 seconds<br>Complete requests:      1000<br>Failed requests:        0<br>Total transferred:      36317000 bytes<br>HTML transferred:       35908000 bytes<br>Requests per second:    7.52 [#/sec] (mean)<br>Time per request:       1330.430 [ms] (mean)<br>Time per request:       133.043 [ms] (mean, across all concurrent requests)<br>Transfer rate:          266.57 [Kbytes/sec] received</pre><pre>Connection Times (ms)<br>              min  mean[+/-sd] median   max<br>Connect:       65   70   3.5     70      89<br>Processing:   670 1219 267.6   1199    6120<br>Waiting:      602 1148 267.5   1128    6049<br>Total:        738 1290 267.9   1269    6188</pre><pre>Percentage of the requests served within a certain time (ms)<br>  50%   1269<br>  66%   1330<br>  75%   1367<br>  80%   1396<br>  90%   1479<br>  95%   1563<br>  98%   1688<br>  99%   1756<br> 100%   6188 (longest request)</pre><p><strong>Server running php-pm with php-7.2 using 4 workers</strong></p><pre>Document Path:          /images/img_growth.png<br>Document Length:        35908 bytes</pre><pre>Concurrency Level:      10<br>Time taken for tests:   20.929 seconds<br>Complete requests:      1000<br>Failed requests:        0<br>Total transferred:      36344000 bytes<br>HTML transferred:       35908000 bytes<br>Requests per second:    47.78 [#/sec] (mean)<br>Time per request:       209.291 [ms] (mean)<br>Time per request:       20.929 [ms] (mean, across all concurrent requests)<br>Transfer rate:          1695.83 [Kbytes/sec] received</pre><pre>Connection Times (ms)<br>              min  mean[+/-sd] median   max<br>Connect:       65   68   2.2     68      81<br>Processing:   134  140  11.3    139     449<br>Waiting:       67   72  10.9     71     383<br>Total:        200  208  11.9    206     516</pre><pre>Percentage of the requests served within a certain time (ms)<br>  50%    206<br>  66%    209<br>  75%    210<br>  80%    211<br>  90%    216<br>  95%    219<br>  98%    225<br>  99%    234<br> 100%    516 (longest request)</pre><p>As you can see the difference between the results is crazy!</p><p><strong>PHP-PM</strong> has shown to be almost <strong>6x</strong> times faster in this particular case, we managed to deploy this improvement to production in less than a few hours with no additional code change, preventing us for rewriting that service in another lang for now which is huge win for us.</p><p>Let me know what you think!</p><p><strong>Bonus Tip:</strong> If you are using AWS S3 like the source of you files, you can improve image read/get time by almost 2x, adding CloudFront for your bucket and use the HTTP adapter for the source instead of reading directly from the bucket, we are using this one: <a href="https://github.com/twistor/flysystem-http">https://github.com/twistor/flysystem-http</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=180fd333cc09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Preact with Laravel Mix]]></title>
            <link>https://medium.com/dev-magazine/using-preact-with-laravel-mix-623c13575c9a?source=rss-cbcb38303231------2</link>
            <guid isPermaLink="false">https://medium.com/p/623c13575c9a</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[laravel-mix]]></category>
            <category><![CDATA[preact]]></category>
            <dc:creator><![CDATA[Joe Cohen]]></dc:creator>
            <pubDate>Mon, 30 Oct 2017 19:44:20 GMT</pubDate>
            <atom:updated>2017-11-10T14:58:01.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6tOzHgqQXH-3NVsZQZHKWA.png" /></figure><p>Preact it’s a “Fast 3kB alternative to React with the same ES6 API.” you can learn more here <a href="https://preactjs.com/">https://preactjs.com/</a></p><p>If you are using Laravel Mix which is an awesome wrapper for Webpack with a simple and clean API shipped with the Laravel Framework, you already have support for React. Preact has a nice tool called <a href="https://github.com/developit/preact-compat">preact-compat</a> that makes really easy <a href="https://preactjs.com/guide/switching-to-preact">transition from React to Preact</a>.</p><p>In this post we will review how to follow the guide to use it with the current React preset that built in Laravel Mix.</p><p>You’ll probably start with the basic config on webpack.mix.js:</p><pre><em>let</em> mix = require(‘laravel-mix’);</pre><pre>mix.react(‘app.js’, ‘dist/js’)<br>   .version();</pre><p>First we have to alias preact-compat to react and react-dom, to do that we need to extend the Webpack config in webpack.mix.js:</p><pre><em>let</em> mix = require(&#39;laravel-mix&#39;);<br></pre><pre>mix.webpackConfig({</pre><pre>   &#39;resolve&#39;: {</pre><pre>     &#39;alias&#39;: {</pre><pre>       &#39;react&#39;: &#39;preact-compat&#39;,</pre><pre>       &#39;react-dom&#39;: &#39;preact-compat&#39;,</pre><pre>     },</pre><pre>    },</pre><pre>  })</pre><pre>  .react(&#39;app.js&#39;, &#39;dist/js&#39;)</pre><pre>  .version();</pre><p>If you have a React app and you are just migrating to Preact your app should be running by now with the same code you had importing react and react-dom.</p><p>If you are starting a project or completely switching to Preac you’ll probably want to change the render function on your app.js to use Preact simple rendering.</p><p>To do that we need to create a .babelrc file in our root project directory to configure the h function of Preact:</p><pre>{</pre><pre>  &quot;plugins&quot;: [</pre><pre>    [&quot;transform-react-jsx&quot;, { &quot;pragma&quot;: &quot;h&quot; }]</pre><pre>  ]</pre><pre>}</pre><p>Now we can start our project with the Preact render function on the app.js file:</p><pre>import { h, render } from &#39;preact&#39;;</pre><pre><em>let</em> root;<br></pre><pre><em>function</em> init() {</pre><pre><em>  let</em> App = require(&#39;./components/App&#39;).default;</pre><pre>  root = render(&lt;App /&gt;, document.body, root);</pre><pre>}</pre><pre><em>// in development, set up HMR:</em></pre><pre>if (<em>module</em>.hot) {<br>  <em>//require(&#39;preact/devtools&#39;);   // turn this on if you want to       enable React DevTools!</em></pre><pre><em>  module</em>.hot.accept(&#39;./components/App&#39;, () =&gt; requestAnimationFrame(init) );</pre><pre>}<br></pre><pre>init();</pre><p>And that’s it, enjoy using Preact with Laravel Mix!</p><p>PS: I’ve made a PR to support Preact natively in Laravel Mix anyway you can use the solution shown in this post to fully work with it <a href="https://github.com/JeffreyWay/laravel-mix/pull/1294">https://github.com/JeffreyWay/laravel-mix/pull/1294</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=623c13575c9a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dev-magazine/using-preact-with-laravel-mix-623c13575c9a">Using Preact with Laravel Mix</a> was originally published in <a href="https://medium.com/dev-magazine">dotdev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>