<?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 Golam Rahman Sagor on Medium]]></title>
        <description><![CDATA[Stories by Golam Rahman Sagor on Medium]]></description>
        <link>https://medium.com/@iamgrsagor?source=rss-92ae3a5ae341------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I3MpPR-Tjo_WIqW0_Qs-UQ.jpeg</url>
            <title>Stories by Golam Rahman Sagor on Medium</title>
            <link>https://medium.com/@iamgrsagor?source=rss-92ae3a5ae341------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 03:40:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iamgrsagor/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[From PostgreSQL to Real-Time Analytics: Inside TigerData (TimescaleDB)]]></title>
            <link>https://iamgrsagor.medium.com/from-postgresql-to-real-time-analytics-inside-tigerdata-timescaledb-9eb05a4602d0?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eb05a4602d0</guid>
            <category><![CDATA[scalable-systems]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 17:12:20 GMT</pubDate>
            <atom:updated>2026-02-08T17:12:20.717Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4gNtm5lJa2cLjIdZxx20g.png" /></figure><p>If your application deals with <strong>time-based data</strong> like logs, metrics, prices, events, analytics, or sensor readings, you’ve probably felt this pain:</p><p>PostgreSQL works great… until your table hits millions or billions of rows and suddenly simple queries slow to a crawl.</p><p>This is exactly the problem <strong>TigerData</strong> solves.</p><p>Formerly known as Timescale, TigerData is built around <strong>TimescaleDB</strong>, a PostgreSQL extension designed specifically for <strong>time-series and real-time analytical workloads</strong>, without forcing you to abandon PostgreSQL or SQL.</p><p>Let’s break this down properly.</p><h3>What Is TigerData?</h3><p>TigerData is a high-performance PostgreSQL platform optimized for <strong>time-series, analytics, and real-time workloads</strong>.</p><p>At a technical level:</p><ul><li>It is <strong>still PostgreSQL</strong></li><li>It uses <strong>standard SQL</strong></li><li>It works with existing PostgreSQL tools and libraries</li></ul><p>But internally, it stores and manages data very differently to stay fast at scale.</p><p>Instead of treating time as just another column, TigerData makes <strong>time a first-class concept</strong>.</p><h3>Why Normal PostgreSQL Struggles with Time-Series Data</h3><p>Traditional PostgreSQL tables store rows sequentially. That’s fine for transactional data, but time-series data behaves differently:</p><ul><li>Data arrives continuously</li><li>Queries almost always filter by time ranges</li><li>Old data is rarely updated</li><li>Datasets grow extremely fast</li></ul><p>As data grows, you usually end up with:</p><ul><li>Manual table partitioning</li><li>Painful retention policies</li><li>Slow aggregations</li><li>Huge storage costs</li></ul><p>TigerData exists to remove that operational burden.</p><h3>How TigerData Solves This</h3><h3>1. Automatic Time-Based Partitioning (Hypertables)</h3><p>Instead of manually partitioning tables, TigerData introduces <strong>hypertables</strong>.</p><p>You create a normal table:</p><pre>CREATE TABLE metrics (<br>  time        TIMESTAMPTZ NOT NULL,<br>  device_id   TEXT,<br>  cpu_usage   DOUBLE PRECISION<br>);</pre><p>Then convert it into a hypertable:</p><pre>SELECT create_hypertable(&#39;metrics&#39;, &#39;time&#39;);</pre><p>That’s it.</p><p>Behind the scenes, TigerData automatically splits the table into time-based chunks. You don’t manage partitions. You don’t rewrite queries. PostgreSQL just keeps working.</p><h3>2. Fast Time-Based Queries</h3><p>Because data is organized by time, queries that filter by time become dramatically faster.</p><pre>SELECT<br>  time_bucket(&#39;5 minutes&#39;, time) AS bucket,<br>  avg(cpu_usage)<br>FROM metrics<br>WHERE time &gt; now() - interval &#39;1 hour&#39;<br>GROUP BY bucket<br>ORDER BY bucket;</pre><p>This kind of query is extremely common in dashboards, monitoring systems, and analytics platforms.</p><p>In a regular PostgreSQL table, this gets expensive as data grows. In TigerData, it’s what the system is designed for.</p><h3>3. Continuous Aggregates for Real-Time Dashboards</h3><p>Dashboards usually run the same aggregation queries repeatedly.</p><p>Instead of recalculating them every time, TigerData lets you create <strong>continuous aggregates</strong>.</p><pre>CREATE MATERIALIZED VIEW metrics_5min<br>WITH (timescaledb.continuous) AS<br>SELECT<br>  time_bucket(&#39;5 minutes&#39;, time) AS bucket,<br>  device_id,<br>  avg(cpu_usage) AS avg_cpu<br>FROM metrics<br>GROUP BY bucket, device_id;</pre><p>These aggregates update automatically as new data arrives.</p><p>Result:</p><ul><li>Faster dashboards</li><li>Lower database load</li><li>No cron jobs or manual refresh logic</li></ul><h3>4. Massive Storage Compression</h3><p>Time-series data compresses extremely well.</p><p>TigerData includes built-in compression policies:</p><pre>ALTER TABLE metrics<br>SET (<br>  timescaledb.compress,<br>  timescaledb.compress_segmentby = &#39;device_id&#39;<br>);</pre><pre>SELECT add_compression_policy(&#39;metrics&#39;, INTERVAL &#39;7 days&#39;);</pre><p>Older data is compressed automatically, often reducing storage by <strong>90% or more</strong>, while remaining fully queryable.</p><h3>Why TigerData Is More Than “Just” Time-Series Now</h3><p>Originally, TimescaleDB focused heavily on metrics and monitoring.</p><p>Today, TigerData positions itself as a <strong>general-purpose PostgreSQL platform for real-time and analytical workloads</strong>, including:</p><ul><li>Observability and logs</li><li>Financial and crypto analytics</li><li>IoT platforms</li><li>AI systems needing historical + real-time context</li><li>Event-driven applications</li></ul><p>You get:</p><ul><li>One database</li><li>One query language</li><li>One ecosystem</li></ul><p>No polyglot data stack unless you actually need one.</p><h3>When Should You Use TigerData?</h3><p>TigerData makes sense when:</p><ul><li>Data grows continuously over time</li><li>Queries frequently filter by time ranges</li><li>You need fast aggregations</li><li>You want to stay in PostgreSQL</li></ul><p>It is not magic. For small datasets, plain PostgreSQL is fine. TigerData shines when scale and time become unavoidable.</p><h3>Final Thoughts</h3><p>TigerData doesn’t ask you to learn a new database. It asks you to <strong>use PostgreSQL the way time-series data demands</strong>.</p><p>If your app lives in time and most apps do, this is one of the cleanest upgrades you can make.</p><p>Thanks for taking the time to read my article!<br> — <a href="https://grsagor.com/">@iamgrsagor</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eb05a4602d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Make Your Next.js App Faster by Loading Heavy Components Only When You Need Them]]></title>
            <link>https://iamgrsagor.medium.com/how-to-make-your-next-js-app-faster-by-loading-heavy-components-only-when-you-need-them-16e31475f6dc?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/16e31475f6dc</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[code-splitting]]></category>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Sun, 10 Aug 2025 08:36:03 GMT</pubDate>
            <atom:updated>2025-08-10T08:36:03.265Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="How to Make Your Next.js App Faster by Loading Heavy Components Only When You Need Them" src="https://cdn-images-1.medium.com/max/1024/1*759rLv1b336OKLkyTuLSqg.png" /><figcaption>How to Make Your Next.js App Faster by Loading Heavy Components Only When You Need Them</figcaption></figure><p>If you’re building a Next.js app, you probably import components at the top of your file like this:</p><pre>import IamGrSagorComponent from &#39;../components/IamGrSagorComponent&#39;<br><br>export default function Page() {<br>  return &lt;IamGrSagorComponent /&gt;<br>}</pre><p>Looks simple and neat, right? But there’s a problem: if IamGrSagorComponent is big or uses a lot of libraries, it gets loaded <strong>right away</strong> with the rest of your page. That means your app takes longer to load, especially for people on slow connections or older devices.</p><h4>Here’s a better way: Dynamic Imports</h4><p>Next.js has a cool feature called dynamic that lets you <strong>load components only when they’re needed</strong>, instead of upfront. It looks like this:</p><pre>import dynamic from &#39;next/dynamic&#39;<br><br>const IamGrSagorComponent = dynamic(() =&gt; import(&#39;../components/IamGrSagorComponent&#39;), {<br>  loading: () =&gt; &lt;p&gt;Loading...&lt;/p&gt;,<br>  ssr: false,<br>})<br><br>export default function Page() {<br>  return &lt;IamGrSagorComponent /&gt;<br>}</pre><h4>What does this do?</h4><ul><li>It splits the big component into a separate file that only downloads when the user actually needs it.</li><li>While it’s loading, the user sees a simple “Loading…” message instead of a blank screen.</li><li>It doesn’t try to render this component on the server, which keeps your initial page load light.</li></ul><h4>Why should you care?</h4><p>Because this simple trick makes your app <strong>load faster and feel smoother</strong>. Instead of forcing users to download all the heavy stuff right away, you let them start interacting with your page sooner.</p><h4>When to use it?</h4><p>Use dynamic imports whenever you have a big component that’s not needed immediately — like charts, maps, video players, or editors. This way, you only load them when the user actually needs them.</p><h4>In short</h4><p>Don’t slow down your app by loading everything upfront. Use Next.js dynamic imports to split your code and load heavy components on demand. Your users will notice the difference.</p><p>Thanks for taking the time to read my article! Try it out — your app’s speed will thank you.<br> — <a href="https://grsagor.com/">@iamgrsagor</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16e31475f6dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Advanced User Search in WordPress Admin Panel with User Meta Data — In Just 1 Minute!]]></title>
            <link>https://iamgrsagor.medium.com/add-advanced-user-search-in-wordpress-admin-panel-with-user-meta-data-in-just-1-minute-7839a80c299a?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/7839a80c299a</guid>
            <category><![CDATA[usermetadata]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[admin-panel]]></category>
            <category><![CDATA[usersearch]]></category>
            <category><![CDATA[wordpress-tips]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Sun, 09 Mar 2025 00:35:23 GMT</pubDate>
            <atom:updated>2025-03-09T00:35:23.302Z</atom:updated>
            <content:encoded><![CDATA[<h3>Add Advanced User Search in WordPress Admin Panel with User Meta Data — In Just 1 Minute!</h3><figure><img alt="Add Advanced User Search in WordPress Admin Panel with User Meta Data — In Just 1 Minute!" src="https://cdn-images-1.medium.com/max/1024/1*2fPbj4UiOWfR5xFdcLPyaQ.png" /><figcaption><strong>Add Advanced User Search in WordPress Admin Panel with User Meta Data — In Just 1 Minute!</strong></figcaption></figure><blockquote>Introduction</blockquote><p>By default, the WordPress admin panel allows searching users by username, email, and display name. However, sometimes we need to search users based on additional metadata, such as phone numbers, company names, or custom profile fields stored in the usermeta table.<br>This article explains how to modify the user search functionality in the WordPress admin panel to include metadata fields. The provided function can be adapted for any meta key, making it flexible for various use cases.</p><blockquote>The Code</blockquote><p>Below is the complete function to enable user search based on any user meta field:</p><pre>function custom_user_search_query($query) {<br>    global $pagenow, $wpdb;<br>    <br>    // Ensure this runs only in the admin panel and on the users listing page<br>    if (is_admin() &amp;&amp; $pagenow === &#39;users.php&#39; &amp;&amp; !empty($_GET[&#39;s&#39;])) {<br>        $search_term = sanitize_text_field($_GET[&#39;s&#39;]); // Sanitize search input<br>        <br>        // Define the meta keys to search within<br>        $meta_keys = [&#39;user_meta_key1&#39;, &#39;user_meta_key2&#39;, &#39;user_meta_key3&#39;];<br>        <br>        $user_ids = [];<br>        <br>        foreach ($meta_keys as $meta_key) {<br>            $results = $wpdb-&gt;get_col($wpdb-&gt;prepare(<br>                &quot;SELECT DISTINCT user_id FROM {$wpdb-&gt;usermeta} WHERE meta_key = %s AND meta_value LIKE %s&quot;,<br>                $meta_key,<br>                &#39;%&#39; . $wpdb-&gt;esc_like($search_term) . &#39;%&#39;<br>            ));<br>            <br>            $user_ids = array_merge($user_ids, $results);<br>        }<br>        <br>        $user_ids = array_unique($user_ids); // Remove duplicate user IDs<br>        <br>        if (!empty($user_ids)) {<br>            $query-&gt;query_vars[&#39;include&#39;] = $user_ids; // Filter users by found meta field matches<br>            unset($query-&gt;query_vars[&#39;search&#39;]); // Remove default search behavior<br>            unset($query-&gt;query_vars[&#39;search_columns&#39;]);<br>        } else {<br>            // Default WordPress search if no metadata matches<br>            $query-&gt;query_vars[&#39;search&#39;] = &#39;*&#39; . $search_term . &#39;*&#39;;<br>            $query-&gt;query_vars[&#39;search_columns&#39;] = [&#39;user_login&#39;, &#39;user_email&#39;, &#39;display_name&#39;];<br>        }<br>    }<br>}<br>add_action(&#39;pre_get_users&#39;, &#39;custom_user_search_query&#39;, 10);</pre><blockquote>Line-by-Line Explanation</blockquote><h4>1. Checking the Search Context</h4><pre>if (is_admin() &amp;&amp; $pagenow === &#39;users.php&#39; &amp;&amp; !empty($_GET[&#39;s&#39;])) {</pre><ul><li>Ensures this function runs only in the WordPress admin panel.</li><li>Checks if the current page is users.php, which is the user management page.</li><li>Ensures a search query (s parameter) is provided.</li></ul><h4>2. Sanitizing the Search Term</h4><pre>$search_term = sanitize_text_field($_GET[&#39;s&#39;]);</pre><ul><li>Prevents potential security vulnerabilities by cleaning user input.</li></ul><h4>3. Defining Meta Keys to Search</h4><pre>$meta_keys = [&#39;billing_phone&#39;, &#39;company_name&#39;, &#39;custom_field&#39;];</pre><ul><li>Specifies which user meta fields should be searched.</li><li>You can add or remove keys based on your requirements.</li></ul><h4>4. Searching for Matching User IDs</h4><pre>foreach ($meta_keys as $meta_key) {<br>    $results = $wpdb-&gt;get_col($wpdb-&gt;prepare(<br>        &quot;SELECT DISTINCT user_id FROM {$wpdb-&gt;usermeta} WHERE meta_key = %s AND meta_value LIKE %s&quot;,<br>        $meta_key,<br>        &#39;%&#39; . $wpdb-&gt;esc_like($search_term) . &#39;%&#39;<br>    ));<br>    <br>    $user_ids = array_merge($user_ids, $results);<br>}</pre><ul><li>Loops through each meta key.</li><li>Executes a SQL query to find users whose metadata contains the search term.</li><li>Merges results into the $user_ids array.</li></ul><h4>5. Removing Duplicate User IDs</h4><pre>$user_ids = array_unique($user_ids);</pre><ul><li>Ensures users are not added multiple times if they match multiple meta fields.</li></ul><h4>6. Modifying the Query Based on Results</h4><pre>if (!empty($user_ids)) {<br>    $query-&gt;query_vars[&#39;include&#39;] = $user_ids;<br>    unset($query-&gt;query_vars[&#39;search&#39;]);<br>    unset($query-&gt;query_vars[&#39;search_columns&#39;]);<br>} else {<br>    $query-&gt;query_vars[&#39;search&#39;] = &#39;*&#39; . $search_term . &#39;*&#39;;<br>    $query-&gt;query_vars[&#39;search_columns&#39;] = [&#39;user_login&#39;, &#39;user_email&#39;, &#39;display_name&#39;];<br>}</pre><ul><li>If matches are found in meta fields, the user query is filtered to include only those users.</li><li>If no matches are found, WordPress performs a default search within username, email, and display name.</li></ul><h4>7. Hooking the Function into WordPress</h4><pre>add_action(&#39;pre_get_users&#39;, &#39;custom_user_search_query&#39;, 10);</pre><ul><li>Attaches the function to the pre_get_users action, modifying the query before user results are fetched.</li></ul><blockquote>How to Customize</blockquote><ul><li>Add or remove meta keys in $meta_keys to search specific fields.</li><li>Modify search_columns if you want to limit the default WordPress search.</li><li>Extend the function to include additional filtering criteria if needed.</li></ul><blockquote>Conclusion</blockquote><p>This function enhances WordPress user search by allowing searches within custom metadata fields. It’s particularly useful for WooCommerce stores, membership sites, or any application where user profiles contain important searchable data beyond usernames and emails.</p><p>Don’t just settle for basic user search functionality; unleash the full potential of WordPress Admin Panel search with User Meta Data today!</p><p>Have any questions or tips you’d like to add?<br>Feel free to drop them in the comments below!</p><p>Thanks for taking the time to read my article!<br> — <a href="https://grsagor.com/">@iamgrsagor</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7839a80c299a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Custom .env File Paths in Laravel: Unlocking New Levels of Flexibility and Security]]></title>
            <link>https://iamgrsagor.medium.com/mastering-custom-env-file-paths-in-laravel-unlocking-new-levels-of-flexibility-and-security-1f6f5ac53b76?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f6f5ac53b76</guid>
            <category><![CDATA[secureenvironmentfiles]]></category>
            <category><![CDATA[dotenvlaravel]]></category>
            <category><![CDATA[laravelenvcustomization]]></category>
            <category><![CDATA[customenvpaths]]></category>
            <category><![CDATA[laravel-security-tips]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Wed, 25 Dec 2024 12:14:14 GMT</pubDate>
            <atom:updated>2024-12-25T12:14:14.933Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Mastering Custom .env File Paths in Laravel: Unlocking New Levels of Flexibility and Security</strong></h3><figure><img alt="Mastering Custom .env File Paths in Laravel: Unlocking New Levels of Flexibility and Security" src="https://cdn-images-1.medium.com/max/1024/1*FaJyu5nTtkHBbozoXtVDAQ.png" /><figcaption>Mastering Custom .env File Paths in Laravel: Unlocking New Levels of Flexibility and Security</figcaption></figure><p>Environment configuration is at the heart of any robust Laravel application. But did you know you can go beyond the default .env file setup to enhance both security and flexibility? This article reveals how to customize the location and name of your .env file, why this can be a game-changer, and how to achieve it seamlessly.</p><blockquote><strong>Why Change the Default .env Path?</strong></blockquote><p>The default .env file in Laravel is convenient, but in certain scenarios, changing its location and name makes perfect sense:</p><ol><li><strong>Enhanced Security:</strong> Storing your environment file outside the root directory or renaming it makes it harder for unauthorized users to identify and access.</li><li><strong>Multi-environment Management:</strong> Customizing the .env file allows you to handle multiple configurations for staging, production, or other environments effortlessly.</li><li><strong>Team Collaboration:</strong> A unique .env file name can prevent accidental overwrites or conflicts in multi-developer teams.</li></ol><p>The best part? The file extension doesn’t matter — whether it’s .env, .config, or .settings, Laravel’s Dotenv package can handle it all.</p><blockquote><strong>How to Change the .env Path and Name</strong></blockquote><p>By default, Laravel’s bootstrap/app.php uses .env in the root directory. To customize this, modify the file as follows:</p><pre>$envPath = __DIR__ . &#39;/../config/env&#39;;<br>$envFile = &#39;my_env_file.settings&#39;;<br>Dotenv::createImmutable($envPath, $envFile)-&gt;load();</pre><p>Boom! Your environment configuration has now been changed successfully. This customization ensures that your application will use the specified file and path for environment configurations.</p><p>The .env file is now expected to be located at: config/env/my_env_file.settings</p><blockquote><strong>Benefits of Customization</strong></blockquote><ol><li><strong>Scalability:</strong> Manage diverse setups for complex applications.</li><li><strong>Security by Obscurity:</strong> Hiding sensitive details in unconventional locations adds an extra layer of defense.</li><li><strong>Adaptability:</strong> Effortlessly switch configurations without modifying your codebase.</li></ol><blockquote><strong>Conclusion</strong></blockquote><p>Whether for security, scalability, or collaboration, customizing your .env file’s location and name can elevate your Laravel project. A simple tweak in bootstrap/app.php is all it takes to tailor your application to your unique needs.</p><p>Don’t just stop at the basics; embrace the full power of Laravel’s environment configuration today.</p><p><strong>Have any questions or tips you’d like to add?<br></strong>Feel free to drop them in the comments below!</p><p>Thanks for taking the time to read my article!<br><strong> — @iamgrsagor</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f6f5ac53b76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Errors to Success: The Debugger’s Guide to Laravel & React]]></title>
            <link>https://iamgrsagor.medium.com/from-errors-to-success-the-debuggers-guide-to-laravel-react-2d4498b33d11?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d4498b33d11</guid>
            <category><![CDATA[laravel-react]]></category>
            <category><![CDATA[bugfreecode]]></category>
            <category><![CDATA[tech-tips]]></category>
            <category><![CDATA[debuggingmasters]]></category>
            <category><![CDATA[code-like-a-pro]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Sat, 07 Dec 2024 11:38:57 GMT</pubDate>
            <atom:updated>2024-12-07T12:46:41.078Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="From Errors to Success: The Debugger’s Guide to Laravel &amp; React" src="https://cdn-images-1.medium.com/max/1024/1*RXrukmoSm0S3A6hmqIngsQ.png" /><figcaption>From Errors to Success: The Debugger’s Guide to Laravel &amp; React</figcaption></figure><p>Debugging can feel like an endless battle against a monster that keeps reappearing in different forms. Whether you’re building a web application with Laravel or React, encountering bugs is a given. But what if you could become a debugging ninja, slashing through errors with precision and confidence? In this article, we’ll dive deep into the essential debugging techniques that will turn you from a frustrated coder into a bug-slaying master. We’ll cover strategies, tools, and best practices for debugging both Laravel and React applications, making your coding journey smoother and less stressful.</p><h3>Effective Debugging Techniques in Laravel</h3><h4>Output Debugging (Variable Values)</h4><p><strong>When to Use:</strong><br>Output debugging is useful when you want to inspect the flow of data or check if variables are being passed correctly through your application. It’s often used when debugging controllers, functions, or general logic.</p><p><strong>Why:</strong><br>When you’re unsure about the content of a variable, request data, or response, dd() (die and dump) or dump() is a quick way to stop execution and display the value.</p><p><strong>How to Use:</strong></p><pre>public function store(Request $request) {<br>  dd($request-&gt;all()); // Outputs all request data<br>}</pre><ul><li><strong>dd()</strong>: This is particularly useful for quick inspection. It outputs the contents and terminates the script execution immediately. It’s helpful for checking the state of a variable at any given point.</li><li><strong>dump()</strong>: Similar to dd(), but it doesn’t terminate the script. Use this when you want to inspect the data while continuing the execution of the script.</li></ul><h4>Inspecting SQL Queries (Database Queries)</h4><p><strong>When to Use</strong>:<br>Use query debugging when you’re facing issues related to database queries, such as incorrect results or failed query execution. This helps you ensure that your queries are being constructed and executed as expected.</p><p><strong>Why</strong>:<br>SQL query debugging gives insight into what is actually being sent to the database. If you suspect issues with SQL queries (e.g., data not being returned, incorrect results), logging the queries can show you exactly what’s happening.</p><p><strong>How to Use</strong>:</p><pre>\DB::enableQueryLog();<br>$data = Model::where(&#39;status&#39;, &#39;active&#39;)-&gt;get();<br>\Log::info(\DB::getQueryLog());</pre><ul><li><strong>\DB::enableQueryLog()</strong>: This method starts recording the queries executed during the request.</li><li><strong>\DB::getQueryLog()</strong>: This retrieves the logged queries. Use this to print the SQL queries to the log, allowing you to see what Laravel is generating behind the scenes.</li><li><strong>\Log::info()</strong>: Outputs the queries to the Laravel log file (storage/logs/laravel.log).</li></ul><h4>Debugging AJAX Requests</h4><p><strong>When to Use</strong>:<br>Use AJAX debugging when you’re handling asynchronous requests in your application, especially when dealing with data that doesn’t load correctly or when there’s an issue with server-client communication.</p><p><strong>Why</strong>:<br>AJAX is a client-server communication method. Debugging AJAX requests ensures that the data sent from the client is valid and that the server is responding with the correct data. If the request fails or the data isn’t updating correctly, inspecting the request and response helps track down the issue.</p><p><strong>How to Use</strong>:</p><p><strong>Test Server Response</strong>: Add a simple return statement in your controller to verify that the server is responding as expected.</p><pre>// In your controller<br>public function testAjax() {<br>    return &#39;Hello World&#39;; // Simple test to verify if the server responds<br>}</pre><p><strong>Inspect Browser’s Network Tab</strong>:</p><ul><li>Open the <strong>Developer Tools</strong> in your browser (usually <strong>F12</strong> or <strong>Ctrl + Shift + I</strong>).</li><li>Go to the <strong>Network</strong> tab.</li><li>Perform the action that triggers the AJAX request.</li><li>Look for the request and check the following:</li></ul><p><strong>Response</strong>: Ensure that the correct data is returned from the server.</p><p><strong>Preview/Payload</strong>: Check the data structure to confirm that the request payload is formatted correctly.</p><p>This helps identify whether the request is reaching the server, whether the server is responding correctly, and whether the response is structured as expected.</p><h4>Exception Handling (Global Error Handling)</h4><p><strong>When to Use:</strong><br>Exception handling is crucial for catching errors in your application that could prevent it from running smoothly, such as database errors, missing files, or invalid user input.</p><p><strong>Why:</strong><br>By catching exceptions, you can log detailed error information or return a user-friendly response instead of crashing the application. Laravel automatically logs exceptions to storage/logs/laravel.log by default.</p><p><strong>How to Use</strong>:</p><p>You can use a try-catch block to handle exceptions and log errors when something goes wrong.</p><pre>public function store(Request $request) {<br>    try {<br>        $post = Post::create($request-&gt;all());<br>        return response()-&gt;json($post);<br>    } catch (\Exception $e) {<br>        Log::error(&#39;Error creating post: &#39; . $e-&gt;getMessage());<br>        return response()-&gt;json([&#39;error&#39; =&gt; &#39;Post creation failed&#39;], 500);<br>    }<br>}</pre><ul><li><strong>Log::error()</strong>: Logs the exception message to the application log file.</li><li><strong>catch block</strong>: Catches any exception thrown during the request and returns a proper error response.</li></ul><h4>Debugging Routes and Requests</h4><p><strong>When to Use:</strong><br>Use this when you suspect issues with route matching, incorrect HTTP methods, or if a route is not being triggered as expected.</p><p><strong>Why:</strong><br>Laravel’s routing system is powerful, but sometimes it’s difficult to track down why certain routes are not being matched, especially if there are complex route definitions or middleware involved.</p><p><strong>How to Use</strong>:</p><ul><li>Check Registered Routes:</li></ul><pre>php artisan route:list</pre><p>This command lists all the routes, HTTP methods, and associated controllers. Use this to ensure the route you’re trying to hit is actually registered.</p><ul><li>Add Route Debugging:</li></ul><pre>Route::get(&#39;/test&#39;, function () {<br>    \Log::info(&#39;Route /test was hit&#39;);<br>    return &#39;Route is working!&#39;;<br>});</pre><p>This will help you verify if the route is being triggered when accessed.</p><h4>Debugging via Laravel Debugbar</h4><p><strong>When to Use:</strong><br>When you need detailed insights into the application’s execution process, including SQL queries, request data, session data, and more.</p><p><strong>Why:</strong><br>Laravel Debugbar is a powerful debugging tool that provides real-time insights into your application while it runs, including the current route, request data, and performance metrics.</p><p><strong>How to Use</strong>:</p><p>Install it via Composer:</p><pre>composer require barryvdh/laravel-debugbar --dev</pre><p>Once installed, you’ll see a <strong>debug bar</strong> in the browser, which displays:</p><ul><li>Request and response details</li><li>SQL queries executed during the request</li><li>Request/response data</li><li>Session data and more</li></ul><h4>Debugging with Xdebug</h4><p><strong>Why:</strong><br>Laravel Debugbar is a powerful debugging tool that provides real-time insights into your application while it runs, including the current route, request data, and performance metrics.</p><p><strong>Why:</strong><br>Xdebug allows you to set breakpoints, step through your code line by line, and inspect variables during runtime. It’s especially useful for more complex logic and issues that require in-depth investigation.</p><p><strong>How to Use</strong>:</p><ul><li><strong>Install Xdebug</strong>: Set up Xdebug on your local development environment (e.g., XAMPP or Homestead).</li><li><strong>Set Breakpoints</strong>: In your PHP code, set breakpoints at locations where you want to pause execution.</li><li><strong>Use a Debugger</strong>: Use an IDE like PhpStorm or Visual Studio Code with Xdebug integration to inspect the variables and execution flow.</li></ul><h3>Effective Debugging Techniques in React</h3><h4>Inspecting State and Props</h4><p><strong>When to Use:</strong><br>Use this method when you’re unsure if the component’s state or props are set correctly or if the UI is rendering based on outdated or incorrect data.</p><p><strong>Why</strong>:<br>React components re-render based on state and props changes, so checking their values during the component lifecycle can help identify issues like unnecessary re-renders or incorrect data being passed down.</p><p><strong>How to Use</strong>:</p><p><strong>Use </strong><strong>console.log()</strong>: You can log the state and props to inspect their values.</p><pre>const MyComponent = (props) =&gt; {<br>    console.log(&#39;Component Props:&#39;, props);<br>    console.log(&#39;Component State:&#39;, props.state);<br>    return &lt;div&gt;{props.name}&lt;/div&gt;;<br>};</pre><p>This is useful when you want to check how props and state are changing over time.</p><p><strong>React Developer Tools</strong>:</p><ul><li><strong>Why</strong>: React Developer Tools (available as a browser extension) allows you to inspect the current state, props, and the component tree in your app.</li><li><strong>How</strong>: Open the <strong>React tab</strong> in Chrome DevTools. You’ll be able to see the components, their states, and props, and track their changes over time.</li></ul><h4>Debugging Component Renders and Re-renders</h4><p><strong>When to Use</strong>:<br>Use this method when you’re experiencing unnecessary or unexpected re-renders, which can lead to performance issues or bugs.</p><p><strong>Why</strong>:<br>React components re-render when state or props change. However, unnecessary re-renders can cause performance bottlenecks. You need to understand why a component is re-rendering, whether it’s due to state changes or other factors.</p><p><strong>How to Use</strong>:</p><ol><li><strong>Use </strong><strong>console.count()</strong>: This is a simple way to count how many times a component renders. Place console.count() inside your component’s render method.</li></ol><pre>const MyComponent = () =&gt; {<br>    console.count(&#39;MyComponent render&#39;);<br>    return &lt;div&gt;MyComponent&lt;/div&gt;;<br>};</pre><p>This will log every time the component renders, which is helpful for debugging re-renders.</p><ul><li><strong>React Developer Tools:</strong> React DevTools offers a feature called <strong>“Highlight updates when components render”</strong>. This will visually highlight the components in your UI when they re-render. This helps pinpoint unnecessary renders.</li><li><strong>React.memo()</strong>: Use React.memo() for functional components to prevent unnecessary re-renders. This can be a good optimization technique when a component’s props haven’t changed.</li></ul><pre>const MyComponent = React.memo(({ name }) =&gt; {<br>    return &lt;div&gt;{name}&lt;/div&gt;;<br>});</pre><h4>Inspecting API Calls (Data Fetching)</h4><p><strong>When to Use</strong>:<br>Use this method when you’re dealing with asynchronous data fetching (such as from an API) and you want to ensure that data is being fetched correctly or returned as expected.</p><p><strong>Why</strong>:<br>Fetching data asynchronously is common in React, and it’s important to debug whether the API call is successful, whether the response structure is correct, and if the component is correctly rendering the fetched data.</p><p><strong>How to Use</strong>:</p><ul><li><strong>Check Network Requests</strong>: Open your browser’s <strong>Developer Tools</strong>, go to the <strong>Network tab</strong>, and inspect the API requests made by your React app.</li></ul><p><strong>Request:</strong> Check the URL, headers, and body being sent.<br><strong>Response:</strong> Validate the response payload and status code. This helps you verify if the API is working as expected.</p><ul><li><strong>Use </strong><strong>console.log() to Inspect the API Response</strong>: Log the response from your API to inspect its structure and the data you’re receiving.</li></ul><pre>useEffect(() =&gt; {<br>    fetch(&#39;https://api.example.com/data&#39;)<br>        .then(response =&gt; response.json())<br>        .then(data =&gt; {<br>            console.log(data); // Log the fetched data<br>            setData(data);<br>        })<br>        .catch(error =&gt; console.log(&#39;Error fetching data:&#39;, error));<br>}, []);</pre><ul><li><strong>Use Async Error Boundaries</strong>: React doesn’t have built-in error boundaries for async operations, but you can manually handle errors:</li></ul><pre>useEffect(() =&gt; {<br>    const fetchData = async () =&gt; {<br>        try {<br>            const response = await fetch(&#39;https://api.example.com/data&#39;);<br>            const data = await response.json();<br>            setData(data);<br>        } catch (error) {<br>            console.error(&#39;Error fetching data:&#39;, error);<br>        }<br>    };<br>    fetchData();<br>}, []);</pre><h4>Handling Errors with Try-Catch</h4><p><strong>When to Use</strong>:<br>Use try-catch blocks when working with asynchronous functions (such as API calls or async operations) that might throw errors.</p><p><strong>Why</strong>:<br>React components can run into errors due to issues like network failures, invalid data, or unexpected responses. Wrapping your async code in try-catch helps you handle those errors gracefully and log them for debugging.</p><p><strong>How to Use</strong>:</p><ul><li><strong>Using </strong><strong>try-catch in Async Functions</strong>: In your async function inside useEffect or event handlers, use try-catch to catch errors that may occur during asynchronous operations.</li></ul><pre>const fetchData = async () =&gt; {<br>    try {<br>        const response = await fetch(&#39;/api/posts&#39;);<br>        if (!response.ok) {<br>            throw new Error(&#39;Network response was not ok&#39;);<br>        }<br>        const data = await response.json();<br>        setPosts(data);<br>    } catch (error) {<br>        console.error(&#39;Error fetching posts:&#39;, error);<br>    }<br>};</pre><ul><li><strong>Gracefully Handle Errors in UI</strong>: You can use the error state to render error messages in the UI.</li></ul><pre>if (error) {<br>    return &lt;div&gt;Error: {error.message}&lt;/div&gt;;<br>}</pre><h4>Debugging React Context and State Management</h4><p><strong>When to Use</strong>:<br>If your app relies on global state management (e.g., React Context, Redux) and you encounter issues with state updates or values not propagating as expected.</p><p><strong>Why</strong>:<br>React Context or Redux is often used for global state, and debugging this can be tricky when values are not updating as expected or components are not re-rendering as they should.</p><p><strong>How to Use</strong>:</p><ul><li><strong>React Developer Tools — Context</strong>: React Developer Tools provides a <strong>Context</strong> tab where you can inspect the values of context providers and consumers. This is useful for debugging issues related to the global state.</li><li><strong>Redux DevTools</strong>: If you’re using Redux, Redux DevTools is a powerful tool for inspecting the state, dispatching actions, and tracking the changes in your store.</li></ul><p><strong>Why:</strong> It helps you visualize the entire state tree and the actions that modify it.<br><strong>How:</strong> You can view the action history and state changes with time travel debugging.</p><h4>Debugging Performance Issues</h4><p><strong>When to Use</strong>:<br>When your React app is slow or unresponsive, especially during complex rendering or updates.</p><p><strong>Why</strong>:<br>Performance bottlenecks can often be traced back to unnecessary renders or expensive operations. Identifying where the problem occurs allows you to optimize rendering and improve the user experience.</p><p><strong>How to Use</strong>:</p><ul><li><strong>React Developer Tools — Profiler</strong>: The <strong>Profiler</strong> tab in React Developer Tools lets you measure the performance of components. It shows how long each render takes and helps you track down performance bottlenecks.</li><li><strong>Use </strong><strong>React.memo() for Functional Components</strong>: If your component doesn’t depend on state or props, wrap it with React.memo() to prevent unnecessary re-renders.</li></ul><pre>const MyComponent = React.memo(({ name }) =&gt; {<br>    return &lt;div&gt;{name}&lt;/div&gt;;<br>});</pre><ul><li><strong>useMemo() and </strong><strong>useCallback()</strong>: Use these hooks to memoize values and functions, preventing unnecessary recalculations and recreations during renders.</li></ul><pre>const memoizedValue = useMemo(() =&gt; computeExpensiveValue(a, b), [a, b]);<br>const memoizedCallback = useCallback(() =&gt; { doSomething(a, b); }, [a, b]);</pre><h4>Debugging with Source Maps</h4><p><strong>When to Use</strong>:<br>When you’re working with a minified or compiled version of your React code and need to debug the original source code.</p><p><strong>Why</strong>:<br>Source maps allow you to debug the unminified source code in the browser’s dev tools, which helps you trace back to the original source in your development environment.</p><p><strong>How to Use</strong>:<br>Ensure that source maps are enabled in your build process (Webpack does this automatically for development builds). In your browser’s DevTools, you can set breakpoints, view variables, and navigate through the original source files.</p><p>Debugging isn’t just about finding and fixing errors — it’s about building the skills and mindset to tackle complex problems with confidence. By mastering the debugging techniques for both Laravel and React, you’ll be able to save time, improve your workflow, and deliver more polished applications. So next time a bug rears its ugly head, remember: you’ve got the tools and skills to conquer it! Debugging is just part of the coding adventure, and with the right approach, you can navigate it like a pro.</p><p><strong>Have any questions or tips you’d like to add?<br></strong>Feel free to drop them in the comments below!</p><p>Thanks for taking the time to read my article!<br><strong> — @iamgrsagor</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d4498b33d11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Struggling to Manage Multiple PHP Versions and Frameworks? Here’s the Perfect Solution!]]></title>
            <link>https://iamgrsagor.medium.com/struggling-to-manage-multiple-php-versions-and-frameworks-heres-the-perfect-solution-58e0fb4e44ca?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/58e0fb4e44ca</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php-development]]></category>
            <category><![CDATA[local-wp]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[wordpress]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Wed, 04 Dec 2024 05:16:17 GMT</pubDate>
            <atom:updated>2024-12-04T06:32:55.117Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Struggling to Manage Multiple PHP Versions and Frameworks? Here’s the Perfect Solution!" src="https://cdn-images-1.medium.com/max/1024/1*mnB0E1irKyXwHdVOgoaAAg.png" /><figcaption>Struggling to Manage Multiple PHP Versions and Frameworks? Here’s the Perfect Solution!</figcaption></figure><p>Are you struggling to manage multiple PHP projects or frameworks running on different PHP versions? You’re not alone! But worry no more — I’ve got the perfect solution for you.</p><p>Let me introduce <strong>Local by WP Engine</strong>, a powerful and free development tool designed primarily for WordPress but versatile enough to support any PHP project or framework. Today, I’ll show you how to use Local to run not just WordPress sites but also raw PHP applications and frameworks like Laravel, all in a step-by-step guide.</p><p>Ready to simplify your development process? Let’s dive in!</p><h3>Download and Install Local</h3><ol><li>Visit <a href="https://localwp.com/">https://localwp.com</a> to download Local.</li><li>Install it on your machine and open the application.</li></ol><h3>Create a WordPress Site</h3><ol><li>Open Local and click the “+” icon or the “Create a New Site” button to start a new site.</li><li>Enter a name for your site (e.g., “MyWordPressSite”) and click “Continue.”</li><li>Choose an environment: select <strong>Preferred</strong> for recommended settings or <strong>Custom</strong> to specify the PHP version, web server type (Apache or Nginx), and MySQL version.</li><li>Set up WordPress admin credentials by entering your admin username, password, and email address. Enable the “Multisite” option if needed.</li><li>Click “Add Site” and wait for Local to create the site, download WordPress core files, and set up the database.</li><li>Once the site is ready, click “Start Site” to run it, and click “Open Site” to view it in your browser. Use “Admin” to access the WordPress dashboard.</li></ol><h3>Locate the Root Directory</h3><ol><li>In the Local application, click the <strong>“Site Folder”</strong> button for your project.</li><li>Open the app/public directory — this is your project’s root directory.</li></ol><h3>Set Up a Laravel Application</h3><ol><li>Delete all files inside the app/public directory.</li><li>Copy your Laravel project files into this directory.</li><li>Open the .env file in your Laravel project and update the database credentials with values from Local&#39;s database tab: host, username, password, and port.</li></ol><h3>Configure the Server</h3><h4><strong>For Apache</strong></h4><ol><li>Create a .htaccess file in the app/public directory.</li><li>Add the following code:</li></ol><pre>&lt;IfModule mod_rewrite.c&gt;<br>Options +FollowSymLinks<br>RewriteEngine On<br>RewriteCond %{REQUEST_URI} !^/public/ <br>RewriteCond %{REQUEST_FILENAME} !-d<br>RewriteCond %{REQUEST_FILENAME} !-f<br>RewriteRule ^(.*)$ /public/$1 <br>#RewriteRule ^ index.php [L]<br>RewriteRule ^(/)?$ public/index.php [L] <br>&lt;/IfModule&gt;</pre><h4>For Nginx</h4><ol><li>Open the /conf/nginx/site.conf.hbs file from project directory.</li><li>Replace the root directive:</li></ol><pre># Old<br>root &quot;{{root}}&quot;;<br># New<br>root &quot;{{root}}/public&quot;;</pre><p>3. Restart Local to apply changes.</p><h3>Start Your Application</h3><ol><li>Start the application from Local.</li><li>Visit the project URL to verify everything is working correctly.</li></ol><h3>Conclusion</h3><p>With <strong>Local</strong>, you can easily manage multi-version PHP applications, including raw PHP, Laravel, and more. It’s simple, efficient, and free. Download Local from <a href="https://localwp.com/">https://localwp.com/</a> and simplify your PHP development today!</p><p><strong>Have any questions or tips you’d like to add?<br></strong>Feel free to drop them in the comments below!</p><p>Thanks for taking the time to read my article!<br><strong> — Sagor</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58e0fb4e44ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing Auto Logout in Laravel When Running the Same Project on Different Ports]]></title>
            <link>https://iamgrsagor.medium.com/fixing-auto-logout-in-laravel-when-running-the-same-project-on-different-ports-f6812461dceb?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6812461dceb</guid>
            <category><![CDATA[sameprojectissue]]></category>
            <category><![CDATA[php-development]]></category>
            <category><![CDATA[autologoutfix]]></category>
            <category><![CDATA[multiple-ports]]></category>
            <category><![CDATA[tips-laravel]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Sun, 01 Dec 2024 15:06:12 GMT</pubDate>
            <atom:updated>2024-12-01T15:06:12.626Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Fixing Auto Logout in Laravel When Running the Same Project on Different Ports" src="https://cdn-images-1.medium.com/max/1024/1*vNT2AKsf8iEc5sXSsP5rkg.png" /><figcaption>Fixing Auto Logout in Laravel When Running the Same Project on Different Ports</figcaption></figure><p>When running the same Laravel application on multiple ports (e.g., 8000 and 9000) in a local environment, you may encounter a frustrating issue: logging into one instance automatically logs you out of the other. This is due to shared session cookies, which conflict between the two ports.</p><p>In this guide, we’ll cover two approaches to fix this issue: a <strong>basic solution</strong> for most use cases and an <strong>advanced solution</strong> for more granular session management.</p><h3><strong>Part 1: Basic Solution</strong></h3><p>The simplest way to solve this issue is by assigning a unique session cookie name for each port. Laravel identifies sessions using the SESSION_COOKIE value set in the .env file.</p><p><strong>1. Modify the .env File</strong></p><p>Open the .env file for each instance and set a unique SESSION_COOKIE value:</p><p>For port <strong>8000</strong>:</p><pre>SESSION_COOKIE=laravel_session_8000</pre><p>For port <strong>9000</strong>:</p><pre>SESSION_COOKIE=laravel_session_9000</pre><p><strong>2. Clear Configuration Cache</strong></p><p>After updating the .env file, clear the configuration cache to apply changes:</p><pre>php artisan config:clear</pre><p>That’s it! Now, each port will use its own session cookie, and logging into one instance will no longer log you out of the other.</p><h3><strong>Part 2: Advanced Solution</strong></h3><p>For scenarios where more isolation is needed (e.g., different environments or separate session storage), you can use advanced configurations.</p><p><strong>1. Use Environment-Specific Files</strong></p><p>Create separate .env files for each instance, such as .env.8000 and .env.9000.</p><ul><li>In .env.8000, set:</li></ul><pre>SESSION_COOKIE=laravel_session_8000</pre><ul><li>In .env.9000, set:</li></ul><pre>SESSION_COOKIE=laravel_session_9000</pre><p>Run each instance with the appropriate .env file:</p><pre>php artisan serve --env=.env.8000 --port=8000  <br>php artisan serve --env=.env.9000 --port=9000</pre><p><strong>2. Separate Session Storage</strong></p><p>If you want complete isolation of sessions:</p><p>Use the file driver with unique session paths for each instance:</p><p>For port <strong>8000</strong>:</p><pre>SESSION_DRIVER=file  <br>SESSION_PATH=storage/framework/sessions_8000</pre><p>For port <strong>9000</strong>:</p><pre>SESSION_DRIVER=file  <br>SESSION_PATH=storage/framework/sessions_9000</pre><p>Create the directories:</p><pre>mkdir -p storage/framework/sessions_8000  <br>mkdir -p storage/framework/sessions_9000  <br>chmod -R 775 storage/framework/sessions_8000  <br>chmod -R 775 storage/framework/sessions_9000</pre><p><strong>3. Clear All Caches</strong></p><p>To ensure all configurations are applied correctly:</p><pre>php artisan cache:clear  <br>php artisan config:clear  <br>php artisan route:clear  <br>php artisan view:clear</pre><p>If you’re running multiple instances of a Laravel application on different ports, the <strong>basic solution</strong> of setting unique session cookie names is often sufficient. However, if you need greater isolation, the <strong>advanced solution</strong> provides more control and flexibility.</p><p>Choose the approach that best fits your needs, and enjoy seamless local development with Laravel!</p><p><strong>Have any questions or tips you’d like to add?<br></strong>Feel free to drop them in the comments below!</p><p>Let’s level up our Laravel projects together.</p><p>Thanks for taking the time to read my article!<br><strong> — Sagor</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6812461dceb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Instantly Reflect Price Updates in WooCommerce by Clearing Transients ]]></title>
            <link>https://iamgrsagor.medium.com/instantly-reflect-price-updates-in-woocommerce-by-clearing-transients-d6fd6bbefb78?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6fd6bbefb78</guid>
            <category><![CDATA[clearwoocommercecache]]></category>
            <category><![CDATA[woocommercetransients]]></category>
            <category><![CDATA[fixwoocommerceissues]]></category>
            <category><![CDATA[woocommercepricefix]]></category>
            <category><![CDATA[priceupdatenotshowing]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Fri, 22 Nov 2024 04:41:01 GMT</pubDate>
            <atom:updated>2024-11-22T17:04:31.247Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Y9T3pnKuyh6lzqoUZ4J3Q.png" /></figure><p>Are your WooCommerce product prices not updating immediately after changes? Here’s the quick fix:</p><h3>The Solution: Clear WooCommerce Transients</h3><p>To instantly reflect updated prices, use the following code:</p><h4>For a Specific Product:</h4><pre>if ( function_exists( &#39;wc_delete_product_transients&#39; ) ) {<br>    wc_delete_product_transients( $product_id ); // Replace $product_id with your product&#39;s ID.<br>}</pre><h4>For All Products:</h4><pre>if ( function_exists( &#39;wc_delete_product_transients&#39; ) ) {<br>    wc_delete_product_transients();<br>}</pre><p>That’s it! This clears WooCommerce’s cached data (transients), ensuring your updated prices are displayed immediately.</p><h3>Why This Happens: WooCommerce Transients Explained</h3><p>WooCommerce uses transients to cache product data for better performance. However, these cached values can delay showing updates, like new prices, on your website.</p><p>You can manually clear these transients by navigating to:<br>WooCommerce &gt; Status &gt; Tools &gt; Clear Transients</p><p>But doing this repeatedly isn’t ideal. Instead, you can programmatically clear transients whenever necessary.</p><h3>Automate Clearing Transients After Price Updates</h3><p>To automate this process, add the following code to your plugin or theme’s functions.php file:</p><pre>add_action( &#39;woocommerce_product_object_updated_props&#39;, &#39;clear_transients_after_price_update&#39; );<br><br>function clear_transients_after_price_update( $product ) {<br>    if ( function_exists( &#39;wc_delete_product_transients&#39; ) ) {<br>        wc_delete_product_transients( $product-&gt;get_id() );<br>    }<br>}</pre><p>This ensures WooCommerce automatically clears the transients for a product whenever its details are updated, showing the new price instantly.</p><h3>How WooCommerce Clears Transients</h3><p>When you click Clear Transients in WooCommerce &gt; Status &gt; Tools, WooCommerce calls the following functions:</p><ol><li>wc_delete_product_transients(): Deletes product-related transients.</li><li>delete_transient(): A WordPress function to delete transients from the database.</li><li>WC_Cache_Helper::delete_version_transients(): Clears version-based transients.</li></ol><p>Using wc_delete_product_transients() programmatically mimics this process, but for individual or all products.</p><h3>Why Clearing Transients Matters</h3><p>Automating transient clearing ensures your product updates are reflected instantly, preventing customer confusion and improving the shopping experience. With this simple approach, you’ll never have to worry about outdated prices showing up on your site.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6fd6bbefb78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fix SSH Auto Exit Caused by sudo Command in Shared Hosting]]></title>
            <link>https://iamgrsagor.medium.com/fix-ssh-auto-exit-caused-by-sudo-command-in-shared-hosting-e04f37ecb843?source=rss-92ae3a5ae341------2</link>
            <guid isPermaLink="false">https://medium.com/p/e04f37ecb843</guid>
            <category><![CDATA[shared-hosting]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[sshloginissue]]></category>
            <category><![CDATA[sshproblem]]></category>
            <category><![CDATA[sshautoexit]]></category>
            <dc:creator><![CDATA[Golam Rahman Sagor]]></dc:creator>
            <pubDate>Mon, 18 Nov 2024 05:30:20 GMT</pubDate>
            <atom:updated>2024-11-18T05:30:20.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8vgkBDf_UcKEhGZ0xOVWUw.png" /><figcaption>Fix SSH Auto Exit Caused by sudo Command in Shared Hosting</figcaption></figure><p>Running restricted sudo commands in shared hosting can cause SSH sessions to exit immediately.</p><p><strong>Solution:</strong></p><p><strong>1. Access .bash_history:</strong> Log in using ssh user@host bash or the hosting panel’s file manager.</p><p><strong>2. Edit History:</strong> Remove the problematic sudo command from .bash_history.</p><pre>// others commands<br>sudo *** // remove this line</pre><p><strong>3. Save and Retry:</strong> Save changes and log in normally.</p><p><strong>Explanation:</strong></p><p>Shared hosting environments restrict sudo commands to maintain security and stability. Running such commands can conflict with server configurations, causing unexpected behavior like session exits. By editing .bash_history to remove the command, you prevent the system from re-triggering the issue during login.</p><p><strong>Tips:</strong></p><p><strong>Avoid Restricted Commands:</strong> Don’t run sudo or similar commands in shared hosting unless explicitly permitted.</p><p><strong>Use the Hosting Panel:</strong> If SSH fails, the hosting panel’s file manager is often a good alternative for accessing and editing files.</p><p><strong>Contact Your Host:</strong> For administrative tasks, reach out to your hosting provider instead of attempting restricted actions.</p><p><strong>Backup Critical Files:</strong> Before making changes, back up important files to avoid accidental loss.</p><p>By understanding shared hosting restrictions and troubleshooting effectively, you can maintain seamless access and avoid disruptions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e04f37ecb843" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>