<?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 Rezaur Rahman on Medium]]></title>
        <description><![CDATA[Stories by Rezaur Rahman on Medium]]></description>
        <link>https://medium.com/@jituboss?source=rss-34a7a3fc984c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fh-mjyal0qztMUww.jpg</url>
            <title>Stories by Rezaur Rahman on Medium</title>
            <link>https://medium.com/@jituboss?source=rss-34a7a3fc984c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:32:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jituboss/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[PHP Non-blocking cURL requests to firebase for Push Notifications]]></title>
            <link>https://medium.com/@jituboss/php-non-blocking-curl-requests-to-firebase-for-push-notifications-8cd613043327?source=rss-34a7a3fc984c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cd613043327</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[curl]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rezaur Rahman]]></dc:creator>
            <pubDate>Wed, 07 Mar 2018 20:48:08 GMT</pubDate>
            <atom:updated>2018-03-08T03:37:58.624Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What is FCM?</strong></h3><p>Firebase Cloud Messaging (FCM) is a handy platform to send push notifications to Android, iOS and Web applications. It’s a very reliable service to deliver messages with no cost.</p><p>FCM has a server-side API that you can call to send messages. See <a href="https://firebase.google.com/docs/cloud-messaging/server">https://firebase.google.com/docs/cloud-messaging/server</a>.</p><h3>Sending Push Notifications</h3><p>If you are building your application backend and the API with a PHP framework, then sending a message can be as simple as using curl to call a HTTP end-point. Consider the following example to send push notification from your server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0193c550ca7f03b3a7fd5677e817f961/href">https://medium.com/media/0193c550ca7f03b3a7fd5677e817f961/href</a></iframe><h3>The Blocking API Call</h3><p>When the Application is live and a number of users are using it, you will find the API calls related to push notifications, from Android or iOS devices are always a bit slower than regular API calls. For example, if there is a messaging API service which sends <em>push notification </em>for new messages, that usually is a <strong>synchronous blocking</strong> API call and waits until the backend completes cURL request to firebase and returns a HTTP response to Application. You can definitely consider tuning cloud stack and decide to scale up with more resources, but the truth is: <strong>in the long run, your application will continue to consume instance’s I/O as the traffic increases.</strong></p><h3><strong>Non-blocking Approach</strong></h3><p>One possible solution is to fork the firebase script into a separate thread but, does PHP support threads? The short answer is No. OK, that’s not 100% true – We can use <a href="http://php.net/manual/en/book.pcntl.php">PCNTL</a> functions. But I prefer to use another easy solution to spawn a background process to perform firebase calls asynchronously.</p><p>The basic idea is to isolate the curl request to firebase into a separate script. Let’s call it background.php. Then in the backend, use the shell_exec function to execute a background job which calls the background.php and handles the curl request. For example, see the following function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34003794207db8f1a4fca3b1aced1be4/href">https://medium.com/media/34003794207db8f1a4fca3b1aced1be4/href</a></iframe><p>In shell_exec, Please notice the use of nohup - to run a command in Unix without getting killed as soon as the function completes running and sending the task to background. nohup always writes to nohup.out in the directory it is being executed if there is output, otherwise to the terminal. So, to make it more simple, let’s redirect the output of the command somewhere else - /dev/null.</p><p>That’s It! Always make sure to give the right file permission while running a background process from your PHP application. If everything is in right place, this implementation will now create a new thread in the background to send curl request to firebase, without waiting for the HTTP response.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cd613043327" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NGINX and PHP-FPM optimization for high traffic web applications]]></title>
            <link>https://medium.com/@jituboss/nginx-and-php-fpm-optimization-for-high-traffic-web-applications-f790bf1b30fb?source=rss-34a7a3fc984c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f790bf1b30fb</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[php-fpm]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Rezaur Rahman]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 09:07:35 GMT</pubDate>
            <atom:updated>2018-02-23T05:56:48.784Z</atom:updated>
            <content:encoded><![CDATA[<p>After using NGINX with PHP-FPM for more than 7 years, i have learned few optimization tricks to keep my stacks up for high traffic</p><h4>TCP vs Unix sockets</h4><p>For better performance, you can choose to switch to Unix domain sockets over TCP sockets</p><pre>upstream backend <br>{ <br> # Unix sockets <br> server unix:/var/run/php56-fpm.sock; </pre><pre> # TCP sockets <br> # server 127.0.0.1:8080; <br>}</pre><p>Sometimes depending on the cloud instance’s I/O speed, TCP ports provide much more scaling than Unix sockets.</p><h4><strong>Adjusting worker processes</strong></h4><p>Determine how many processors are there for your instance</p><pre>cat /proc/cpuinfo | grep processor</pre><p>and set the worker_processes in your <em>nginx.conf</em> file to the number of cores. Also increase the number of worker_connections and set multi_accept to <em>ON</em></p><pre># if you have 32 cores <br>worker_processes 32; </pre><pre># connections per worker <br>events <br>{ <br> worker_connections 8192; <br> multi_accept on; <br>}</pre><h4>Upstream load balancing</h4><p>To produce higher throughput on a single instance, you can try multiple backends</p><pre>upstream backend { <br>  server unix:/var/run/php56-fpm.sock1 weight=100 max_fails=5 fail_timeout=5; <br>  server unix:/var/run/php56-fpm.sock2 weight=100 max_fails=5 fail_timeout=5; <br>}</pre><p>For example, if you have two backends, then you will have to setup two php-fpm pools at /etc/php5/fpm/pool.d/www1.conf and /etc/php5/fpm/pool.d/www2.conf</p><h4>No access logging</h4><p>Disable all type of access logging for all of your servers. They consume your instance’s disk space fast and reduce system I/O speed. You can keep only error logging to debug fatal errors or warnings.</p><pre>access_log off; <br>log_not_found off; <br>error_log /var/log/nginx-error.log warn;</pre><p>If you can’t afford to turn off access log files, at least buffer them</p><pre>access_log /var/log/nginx/access.log main buffer=32k;</pre><p><strong>Enabling compression (GZip)</strong></p><p>How fast a website will load depends on the size of all of the files that have to be downloaded by the browser. Reducing the size of files to be transmitted can make the website load a lot faster. To do this, you need to enable compression</p><pre>gzip on;</pre><pre>gzip_proxied any;</pre><pre>gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;</pre><pre>gzip_vary on;</pre><pre>gzip_disable “MSIE [1–6]\.(?!.*SV1)”;</pre><h4>Tuning SYSCTL</h4><p>Any cloud instance out of box is not optimized to make full use of available capacity. This means default setup might fail under high load. So we need to tweak system configuration for maximum concurrency</p><pre>nano /etc/sysctl.conf</pre><p>And add the following values</p><pre># new values<br>net.nf_conntrack_max = 131072<br>net.core.somaxconn = 131072<br>kernel.msgmnb = 131072<br>kernel.msgmax = 131072<br>fs.file-max = 131072</pre><h4>Monitoring logs</h4><p>Tail, tail and tail again, it’s very much important to monitor what is actually happing on your system all the time. If you are optimizing your existing web server then always keep your eyes open to find misconfigurations and errors.</p><p>In one window</p><pre>tail -f /var/log/nginx/error.log</pre><p>And in other windows</p><pre>tail -f /var/log/php-fpm/error.log</pre><pre>tail -f /var/log/php-fpm/www-error.log</pre><p>Also <a href="https://mmonit.com/monit/">Monit</a> is a very useful monitoring tool that helps rescue your server from failed process. Install and configure it for the services you want to keep up all the time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f790bf1b30fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>