<?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>DEV Community: Mahfuzur Rahman</title>
    <description>The latest articles on DEV Community by Mahfuzur Rahman (@devmahfuz).</description>
    <link>https://dev.to/devmahfuz</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%2F1179723%2F0a789017-b78b-418b-bac7-89bd66fe9f01.jpg</url>
      <title>DEV Community: Mahfuzur Rahman</title>
      <link>https://dev.to/devmahfuz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devmahfuz"/>
    <language>en</language>
    <item>
      <title>Exploring MySQL Full-Text Search and Its Implementation in Laravel</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Sun, 02 Feb 2025 06:12:43 +0000</pubDate>
      <link>https://dev.to/devmahfuz/exploring-mysql-full-text-search-and-its-implementation-in-laravel-4icl</link>
      <guid>https://dev.to/devmahfuz/exploring-mysql-full-text-search-and-its-implementation-in-laravel-4icl</guid>
      <description>&lt;p&gt;Imagine you’re building a news website or a blog, and you need a fast and efficient way to search through thousands (or even millions) of articles. Traditional &lt;code&gt;LIKE&lt;/code&gt; queries in MySQL won’t cut it they’re slow and inefficient. This is where &lt;strong&gt;MySQL Full-Text Search (FTS)&lt;/strong&gt; comes into play! 🚀&lt;/p&gt;

&lt;p&gt;Full-Text Search is MySQL’s built-in solution for powerful, efficient text searching. In this article, we’ll break down what it is, how it works, and how you can implement it in Laravel.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is MySQL Full-Text Search?
&lt;/h2&gt;

&lt;p&gt;Full-Text Search (FTS) is a feature in MySQL that allows you to perform advanced text-based queries using &lt;strong&gt;indexes&lt;/strong&gt; rather than scanning entire tables. This makes searches much faster compared to the traditional LIKE operator.&lt;/p&gt;

&lt;h2&gt;
  
  
  How It Works 🔍
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Indexing: MySQL creates a FULLTEXT index on specific columns.&lt;/li&gt;
&lt;li&gt;Tokenization: Text is broken into words (tokens) and stored in an index.&lt;/li&gt;
&lt;li&gt;Ranking: When a search query is executed, MySQL retrieves results based on relevance scoring.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Full-Text Search Modes
&lt;/h2&gt;

&lt;p&gt;MySQL provides two main modes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Natural Language Mode (Default) Returns results ranked by relevance.&lt;/li&gt;
&lt;li&gt;Boolean Mode — Allows custom search logic using operators like +, -, OR, NOT.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setting Up Full-Text Search in Laravel
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Creating the Database Table&lt;/strong&gt;&lt;br&gt;
First, create a migration to add a FULLTEXT index to your table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Schema::create('news', function (Blueprint $table) {
    $table-&amp;gt;id();
    $table-&amp;gt;string('title');
    $table-&amp;gt;text('content');
    $table-&amp;gt;timestamps();

    $table-&amp;gt;fullText(['title', 'content']); // Adding FULLTEXT index
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Performing a Full-Text Search&lt;/strong&gt;&lt;br&gt;
You can now use MySQL’s MATCH() function in Laravel queries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$search = 'election results';

$results = DB::table('news')
    -&amp;gt;whereRaw("MATCH(title, content) AGAINST(? IN NATURAL LANGUAGE MODE)", [$search])
    -&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query will return articles ranked by relevance.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Using Boolean Mode for Advanced Searches
&lt;/h2&gt;

&lt;p&gt;Need more control? Use Boolean Mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$search = '+election -fake';

$results = DB::table('news')
    -&amp;gt;whereRaw("MATCH(title, content) AGAINST(? IN BOOLEAN MODE)", [$search])
    -&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures results must contain “election” but must not contain “fake.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Full-Text Search in Eloquent&lt;/strong&gt;&lt;br&gt;
Want a cleaner approach? Use Eloquent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class News extends Model
{
    public function scopeSearch($query, $keywords)
    {
        return $query-&amp;gt;whereRaw("MATCH(title, content) AGAINST(? IN NATURAL LANGUAGE MODE)", [$keywords]);
    }
}

$articles = News::search('technology trends')-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes it reusable across your application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Optimizing Full-Text Search Performance&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use Short Columns: Store only necessary text in the FULLTEXT index.&lt;/li&gt;
&lt;li&gt;Limit Results: Always paginate or limit query results.&lt;/li&gt;
&lt;li&gt;Consider External Search Engines: If your dataset is huge, try Meilisearch or Elasticsearch.&lt;/li&gt;
&lt;li&gt;MySQL Full-Text Search is a powerful tool for fast and efficient text searching. When combined with Laravel, it provides an easy and flexible way to implement advanced search features.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, whether you’re building a news portal, a blog, or an e-commerce site, leveraging Full-Text Search can significantly enhance the user experience.&lt;/p&gt;

&lt;p&gt;And with Redis Caching, it will be a lot faster. &lt;strong&gt;Happy Coding!!!!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>learning</category>
      <category>laravel</category>
      <category>mysql</category>
      <category>php</category>
    </item>
    <item>
      <title>Docker Multi-Container Deployment with GitHub Actions in Laravel</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Mon, 20 Jan 2025 07:03:55 +0000</pubDate>
      <link>https://dev.to/devmahfuz/docker-multi-container-docker-multi-container-deployment-with-github-actions-1jko</link>
      <guid>https://dev.to/devmahfuz/docker-multi-container-docker-multi-container-deployment-with-github-actions-1jko</guid>
      <description>&lt;p&gt;In today’s tech world, applications often rely on multiple interconnected services (containers) to function seamlessly — think of a web app working alongside a database, a cache, and a load balancer. Deploying such a multi-container application can seem daunting, but with GitHub Actions, you can set up a smooth CI/CD pipeline to deploy your app to production. Here’s a casual walk-through of how it’s done.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Multi-Container Deployment?
&lt;/h2&gt;

&lt;p&gt;It’s the process of deploying multiple Docker containers that work together as a system. For instance, a Laravel app might use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A container for the application code.&lt;/li&gt;
&lt;li&gt;Another is for the MySQL database.&lt;/li&gt;
&lt;li&gt;Nginx is used to serve static files and proxying requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before jumping into deployment:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Dockerize Your Application: Ensure each service has a Dockerfile.&lt;/li&gt;
&lt;li&gt;Set Up Docker Compose: A docker-compose.yml file to orchestrate the containers.&lt;/li&gt;
&lt;li&gt;Provision a Server: A VPS (like DigitalOcean or AWS Lightsail) with Docker and Docker Compose installed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 2: Build Your GitHub Actions Workflow
&lt;/h2&gt;

&lt;p&gt;GitHub Actions lets you automate testing, building, and deploying. Here’s a simple workflow for deploying a Dockerized app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Multi-Container Deployment
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      # Checkout code
      - name: Checkout Repository
        uses: actions/checkout@v2
      # Build Docker Images
      - name: Build Docker Images
        run: |
          docker-compose -f docker-compose.yml build
      # Push Images to Docker Hub
      - name: Push Images
        env:
          DOCKER_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
        run: |
          echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
          docker-compose -f docker-compose.yml push
      # Deploy to VPS
      - name: Deploy to VPS
        uses: appleboy/ssh-action@v0.1.4
        with:
          host: ${{ secrets.VPS_SERVER_IP }}
          username: ${{ secrets.VPS_USERNAME }}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          script: |
            cd /path/to/your/app
            docker-compose pull
            docker-compose down
            docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Trigger on Push: The workflow starts whenever you push to the main branch.&lt;/li&gt;
&lt;li&gt;Build Docker Images: Images for each container are built using docker-compose.yml.&lt;/li&gt;
&lt;li&gt;Push to Docker Hub: Built images are uploaded to Docker Hub (or another container registry).&lt;/li&gt;
&lt;li&gt;Deploy to VPS: The workflow logs into your server via SSH, pulls the latest images, and restarts the containers using docker-compose.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why This Workflow Rocks
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Automation: No manual SSH-ing or running commands — it’s all automated.&lt;/li&gt;
&lt;li&gt;Consistency: Every deployment uses the same images built in CI, ensuring consistency.&lt;/li&gt;
&lt;li&gt;Simplicity: Docker Compose simplifies managing multi-container apps.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that’s it! With this workflow, you can confidently deploy your multi-container app without breaking a sweat. Happy deploying! &lt;/p&gt;

</description>
      <category>docker</category>
      <category>dockerdeployment</category>
      <category>laravel</category>
      <category>devops</category>
    </item>
    <item>
      <title>What Happens When You Run “php artisan serve” in Laravel?</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Mon, 02 Dec 2024 18:58:25 +0000</pubDate>
      <link>https://dev.to/devmahfuz/what-happens-when-you-run-php-artisan-serve-in-laravel-2346</link>
      <guid>https://dev.to/devmahfuz/what-happens-when-you-run-php-artisan-serve-in-laravel-2346</guid>
      <description>&lt;p&gt;Laravel is one of the most popular PHP frameworks, making web development efficient and enjoyable. As a developer, you’ve likely used the php artisan serve command to quickly start a local development server. But have you ever wondered what happens behind the scenes when you run this command? Let’s explore this in detail, step by step, understand how Laravel identifies and runs the ServeCommand, and dive into what PHP’s built-in server is and how it compares to traditional web servers like Nginx or Apache.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is php artisan serve?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;php artisan serve&lt;/code&gt; command is a Laravel feature that starts a local web server for your project. It uses PHP’s built-in server to make your Laravel application accessible at a specific address (e.g., &lt;code&gt;http://127.0.0.1:8000&lt;/code&gt;) during development.&lt;/p&gt;

&lt;p&gt;This command is especially useful for local development because it doesn’t require setting up a full-fledged web server like Nginx or Apache.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-Step Process: What Happens When You Run php artisan serve?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. User Runs the Command&lt;/strong&gt;&lt;br&gt;
When you type &lt;code&gt;php artisan serve&lt;/code&gt; in the terminal, Laravel's Artisan Console a command line tool for Laravel, kicks into action. It’s like a toolbox with various commands to assist in building, testing, and running Laravel applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Artisan Entry Point&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The artisan file in your project’s root directory acts as the entry point for all Artisan commands.&lt;/li&gt;
&lt;li&gt;When you run php artisan serve, the artisan file does the following:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Includes Composer’s autoloader (&lt;code&gt;vendor/autoload.php&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Bootstraps the Laravel framework using &lt;code&gt;bootstrap/app.php&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;3. Artisan Finds the ServeCommand&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Laravel registers all Artisan commands when the application boots. For built-in commands like serve, Laravel registers them in the &lt;code&gt;Illuminate\Foundation\Providers\ArtisanServiceProvider&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;This provider maps the command name (&lt;code&gt;serve&lt;/code&gt;) to its corresponding class (&lt;code&gt;Illuminate\Foundation\Console\ServeCommand&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Command Resolution and Autoloading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;ServeCommand&lt;/code&gt; is located in the &lt;code&gt;vendor/laravel/framework&lt;/code&gt; directory under the namespace &lt;code&gt;Illuminate\Foundation\Console&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Laravel uses Composer’s PSR-4 autoloading configuration to locate and load the class.&lt;/li&gt;
&lt;li&gt;This allows the ServeCommand class to be loaded without the full Laravel framework being fully initialized yet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Preparing the Server
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;ServeCommand&lt;/code&gt; configures the PHP built-in server:&lt;/li&gt;
&lt;li&gt;Host: Default is &lt;code&gt;127.0.0.1&lt;/code&gt; (localhost).&lt;/li&gt;
&lt;li&gt;Port: Default is &lt;code&gt;8000&lt;/code&gt; (or a custom one via &lt;code&gt;--port&lt;/code&gt; option).&lt;/li&gt;
&lt;li&gt;Document Root: Points to the &lt;code&gt;public&lt;/code&gt; directory where Laravel’s entry file (&lt;code&gt;index.php&lt;/code&gt;) resides.&lt;/li&gt;
&lt;li&gt;Internally, the command executes:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php -S 127.0.0.1:8000 -t public server.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;php -S&lt;/code&gt; Starts PHP’s built-in server.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-t public&lt;/code&gt; Specifies the document root.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;server.php&lt;/code&gt;: A router file to handle dynamic requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Handling Requests
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;server.php&lt;/code&gt; file acts as a router:&lt;/li&gt;
&lt;li&gt;If the requested file (e.g., CSS, JS) exists, it is served directly.&lt;/li&gt;
&lt;li&gt;Otherwise, requests are forwarded to &lt;code&gt;index.php&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Laravel Processes the Request
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;index.php&lt;/code&gt; file initializes Laravel’s framework and handles incoming HTTP requests.&lt;/li&gt;
&lt;li&gt;It routes the request to the appropriate controller, processes the logic, and generates a response (e.g., HTML or JSON).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Response is Sent Back
&lt;/h2&gt;

&lt;p&gt;The Laravel response is sent back to the PHP built-in server, which then delivers it to the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is PHP’s Built-In Server?
&lt;/h2&gt;

&lt;p&gt;PHP’s built-in server is a simple development server introduced in PHP 5.4. It’s designed to help developers test applications without needing to install or configure a full web server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of PHP Built-In Server:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ease of Use: Start it with a single command (&lt;code&gt;php -S&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Dynamic and Static Files: Serves both PHP scripts and static files like images or stylesheets.&lt;/li&gt;
&lt;li&gt;Custom Routing: Allows custom handling of requests through a router script (like Laravel’s &lt;code&gt;server.php&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Comparison: PHP Built-In Server vs. Nginx/Apache
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: The PHP Built-in Server is For Development purposes only. Nginx/Apache is for both Production-ready and development.&lt;/li&gt;
&lt;li&gt;Performance: The PHP built-in server is Single-threaded (one request at a time) and Nginx/Apache is Multi-threaded (handles many requests concurrently)&lt;/li&gt;
&lt;li&gt;Configuration: The PHP built-in server minimal setup requires. nginx/Apache needs configuration files.&lt;/li&gt;
&lt;li&gt;Advanced Features: The PHP built-in server is Limited (e.g., no caching). Nignx/Apache can be used for Caching, load balancing, and more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While this setup is convenient, it’s meant only for development. For live applications, web servers like Nginx or Apache provide the scalability and performance necessary for handling production traffic.&lt;/p&gt;

&lt;p&gt;P.S. It always interests me to learn how things work behind the scenes. This helps me understand what is actually happening when I am building an application. You can read my other articles.&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>What is PHP Fiber? Does PHP Fiber Really Give You Asynchronous Execution?</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Fri, 29 Nov 2024 19:04:58 +0000</pubDate>
      <link>https://dev.to/devmahfuz/what-is-php-fiber-does-php-fiber-really-give-you-asynchronous-execution-12ia</link>
      <guid>https://dev.to/devmahfuz/what-is-php-fiber-does-php-fiber-really-give-you-asynchronous-execution-12ia</guid>
      <description>&lt;p&gt;When PHP 8.1 introduced Fibers, many developers wondered if they were a solution to PHP’s long-standing limitation as a single-threaded, synchronous language. Could Fibers make PHP asynchronous, like JavaScript with its event loops or Node.js? The answer is subtle: Fibers don’t provide true asynchronous execution, but they are a powerful tool for managing tasks more efficiently. Let’s explore this concept in detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are PHP Fibers?
&lt;/h2&gt;

&lt;p&gt;Fibers are a mechanism for implementing cooperative multitasking in PHP. They allow you to pause and resume specific parts of code without blocking the entire PHP process. Think of a Fiber as a specialized function that can “yield” control back to the main program and then continue execution from where it left off when requested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features of Fibers:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can start, pause, and resume their execution.&lt;/li&gt;
&lt;li&gt;They operate within the same PHP process and do not introduce multi-threading.&lt;/li&gt;
&lt;li&gt;They are particularly useful for structuring non-blocking code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What Happens When a Fiber Is Paused?
&lt;/h2&gt;

&lt;p&gt;When a Fiber is paused using Fiber::suspend(), the control returns to the main PHP script. This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The main process is free to continue executing other parts of your program.&lt;/li&gt;
&lt;li&gt;The Fiber’s execution is halted temporarily, waiting for a resume() call.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fiber = new Fiber(function () {
    echo "Fiber started\n";
    Fiber::suspend();
    echo "Fiber resumed\n";
});

echo "Before Fiber\n";
$fiber-&amp;gt;start();
echo "After Fiber Start\n";
$fiber-&amp;gt;resume();
echo "After Fiber Resume\n";
Output:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before Fiber
Fiber started
After Fiber Start
Fiber resumed
After Fiber Resume
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what’s happening:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fiber::suspend() pauses the Fiber. Execution shifts back to the main script after $fiber-&amp;gt;start().&lt;/li&gt;
&lt;li&gt;The main script continues running (“After Fiber Start”).&lt;/li&gt;
&lt;li&gt;When resume() is called, the Fiber picks up where it left off and completes its task.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Does Resuming a Fiber Block the Main Process?
&lt;/h2&gt;

&lt;p&gt;Yes, but only temporarily. When you call Fiber::resume(), the Fiber runs synchronously within the main PHP process. During this time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Other parts of your script (or other Fibers) cannot execute until the Fiber completes or pauses again.&lt;/li&gt;
&lt;li&gt;The execution of the Fiber is blocking because PHP remains single-threaded.
For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fiber = new Fiber(function () {
    echo "Processing Fiber...\n";
    sleep(2); // Simulates a blocking task
    echo "Fiber Done\n";
});

echo "Before Fiber\n";
$fiber-&amp;gt;start();
echo "Between Fiber Start and Resume\n";
$fiber-&amp;gt;resume();
echo "After Fiber\n";
Output:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before Fiber
Processing Fiber...
Fiber Done
Between Fiber Start and Resume
After Fiber
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the Fiber blocks the main process during the sleep(2) call. So, while Fibers provide a way to structure code for efficiency, they don’t magically enable parallel or truly asynchronous execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Are Fibers Still “Non-Blocking”?
&lt;/h2&gt;

&lt;p&gt;The term “non-blocking” refers to how Fibers enable better task management, not parallel execution. A Fiber doesn’t block the main process while it’s paused; instead, control is handed back to the main script or an event loop.&lt;/p&gt;

&lt;p&gt;This is particularly useful for libraries or frameworks that use event-driven architectures, like ReactPHP or Amp, where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Long-running or waiting tasks (e.g., database queries, API calls) can be suspended.&lt;/li&gt;
&lt;li&gt;Other tasks can continue running in the meantime.&lt;/li&gt;
&lt;li&gt;Once the task is ready, the Fiber is resumed, and its execution continues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Imagine you are a chef preparing multiple dishes:&lt;br&gt;
You start cooking a dish but pause to wait for something to boil.&lt;br&gt;
While waiting, you begin preparing another dish.&lt;br&gt;
When the first dish is ready, you return to it and continue cooking.&lt;/p&gt;

&lt;p&gt;Similarly, Fibers allows PHP to “pause” a task and return to it later without holding up the entire process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Fibers Are Not Truly Asynchronous.
&lt;/h2&gt;

&lt;p&gt;Unlike asynchronous programming in JavaScript or Node.js, where tasks can run in parallel using threads or an event loop, Fibers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Execute synchronously within a single PHP process.&lt;/li&gt;
&lt;li&gt;Provide cooperative multitasking by allowing the developer to manually control task suspension and resumption.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words:&lt;br&gt;
Fibers don’t introduce parallelism (tasks still run one at a time).&lt;br&gt;
They are a tool for managing and structuring non-blocking code more efficiently.&lt;br&gt;
While PHP Fibers don’t make PHP truly asynchronous, they are a powerful addition to the language.&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>laravel</category>
      <category>webdev</category>
    </item>
    <item>
      <title>PHP is a Single-Threaded Language, So How Does Laravel Handle Queue Jobs Asynchronously?</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Thu, 28 Nov 2024 12:47:45 +0000</pubDate>
      <link>https://dev.to/devmahfuz/php-is-a-single-threaded-language-so-how-does-laravel-handle-queue-jobs-asynchronously-5dgc</link>
      <guid>https://dev.to/devmahfuz/php-is-a-single-threaded-language-so-how-does-laravel-handle-queue-jobs-asynchronously-5dgc</guid>
      <description>&lt;p&gt;PHP is known as a single-threaded language, meaning it can only execute one task at a time within a single process. However, Laravel provides a robust queue system to handle multiple tasks “asynchronously.” If PHP is single-threaded, how does Laravel achieve this magic? Let’s break it down in simple terms.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a PHP Process?
&lt;/h2&gt;

&lt;p&gt;Before diving into queues, we need to understand what a PHP process is.&lt;/p&gt;

&lt;p&gt;A process is like a worker hired to complete a task. When you execute a PHP script (e.g., php my_script.php), the operating system creates a new process. This process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loads the PHP script.&lt;/li&gt;
&lt;li&gt;Executes the code step-by-step.&lt;/li&gt;
&lt;li&gt;Stops and “dies” when the task is done.
For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "Hello World!";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run this script, PHP starts a process, displays “Hello World!”, and then the process ends.&lt;/p&gt;

&lt;h2&gt;
  
  
  PHP in Web Applications
&lt;/h2&gt;

&lt;p&gt;In web applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A web server (like Apache or Nginx) receives an HTTP request from a browser.&lt;/li&gt;
&lt;li&gt;The server creates a new PHP process to handle the request.&lt;/li&gt;
&lt;li&gt;PHP processes the request (e.g., fetching data from a database or rendering a page).&lt;/li&gt;
&lt;li&gt;The process ends after sending a response to the browser.&lt;/li&gt;
&lt;li&gt;PHP processes are short-lived. They handle one request at a time and then stop. This design makes PHP simple and efficient for web applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Single-Threaded?
&lt;/h2&gt;

&lt;p&gt;PHP is single-threaded, meaning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A PHP process can only handle one task at a time.&lt;/li&gt;
&lt;li&gt;It doesn’t perform multiple tasks simultaneously in the same process.
For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "Task 1";
// Waits for Task 1 to finish before starting Task 2
echo "Task 2";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PHP executes Task 1 first. Only after it’s done does it move to Task 2. This behavior is different from languages like JavaScript, where tasks can run in parallel in the same process.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does Laravel Handle Queues Then?
&lt;/h2&gt;

&lt;p&gt;Laravel’s queue system allows you to run multiple tasks in the background without blocking the main application. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sending emails.&lt;/li&gt;
&lt;li&gt;Processing image uploads.&lt;/li&gt;
&lt;li&gt;Sending notifications.
These tasks run in the background, so your main application can respond to users faster.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But PHP can only handle one task at a time, right? How does Laravel make it seem asynchronous? The answer lies in workers and multiple processes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Worker?
&lt;/h2&gt;

&lt;p&gt;A worker in Laravel is a long-running PHP process that listens for jobs in a queue and executes them.&lt;/p&gt;

&lt;p&gt;When you run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan queue:work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A new PHP process (or worker) starts. This process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connects to the queue system (like Redis or a database).&lt;/li&gt;
&lt;li&gt;Waits for new jobs (tasks) to arrive in the queue.&lt;/li&gt;
&lt;li&gt;Picks up and processes jobs one by one. 
Example: Imagine you have a task to send 1,000 emails:
The main application sends 1,000 jobs to the queue.
A worker process picks up one job, sends the email, and moves to the next job.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Does Laravel Achieve Asynchronous Behavior?
&lt;/h2&gt;

&lt;p&gt;Laravel achieves “asynchronous” behavior by running multiple workers at the same time. Each worker is a separate PHP process.&lt;/p&gt;

&lt;p&gt;Here’s how it works:&lt;br&gt;
When you run php artisan queue:work, it starts with one worker (one PHP process).&lt;br&gt;
You can start multiple workers to process jobs in parallel on different tabs locally and in production using the process manager like the supervisor.&lt;br&gt;
This will start multiple PHP processes. Each worker handles jobs independently, making it seem like tasks are running simultaneously.&lt;/p&gt;
&lt;h2&gt;
  
  
  What Happens When a Job is Queued?
&lt;/h2&gt;

&lt;p&gt;When you queue a job in Laravel, here’s what happens step-by-step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Job Creation: 
The job (e.g., send an email) is serialized (converted into a storable format) and added to the queue backend (like Redis or a database).&lt;/li&gt;
&lt;li&gt;Worker Polls the Queue:
Workers continuously check the queue for new jobs.
If a job is found, the worker picks it up.&lt;/li&gt;
&lt;li&gt;Job Execution:
The worker deserializes the job and runs its handle() method.
Once done, the job is marked as completed.&lt;/li&gt;
&lt;li&gt;Job Completion:
The worker removes the job from the queue.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the job fails, Laravel retries it or moves it to a “failed jobs” list (based on your configuration).&lt;/p&gt;

&lt;p&gt;Example Scenario: Sending Emails&lt;br&gt;
Imagine you have a Laravel application where users submit a contact form. When the form is submitted:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The main application processes the form and responds to the user immediately.&lt;/li&gt;
&lt;li&gt;Instead of sending the email right away, it adds the email-sending task to a queue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the background:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A worker picks up the email-sending job.&lt;/li&gt;
&lt;li&gt;Sends the email.&lt;/li&gt;
&lt;li&gt;Moves to the next job.&lt;/li&gt;
&lt;li&gt;This way, the user doesn’t have to wait for the email to be sent, making the app faster.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  How Do Workers Run in Production?
&lt;/h2&gt;

&lt;p&gt;In production, Laravel workers are managed by tools like Supervisor. The supervisor keeps workers running 24/7 and restarts them if they crash.&lt;/p&gt;

&lt;p&gt;Supervisor Configuration Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[program:laravel-worker]
command=php /path/to/artisan queue:work --tries=3
numprocs=5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;command: Runs the queue:work command.&lt;br&gt;
numprocs=5: Starts 5 workers (5 PHP processes) to handle jobs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is It Truly Asynchronous?
&lt;/h2&gt;

&lt;p&gt;Technically, Laravel queues are not asynchronous in the way JavaScript or Node.js handle tasks. Instead:&lt;/p&gt;

&lt;p&gt;Each worker handles one job at a time.&lt;br&gt;
Multiple workers (processes) provide parallelism, giving the appearance of asynchronous execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Points to Remember
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PHP is single-threaded, so a single PHP process handles one task at a time.&lt;/li&gt;
&lt;li&gt;Laravel uses workers (long-running PHP processes) to process queue jobs.&lt;/li&gt;
&lt;li&gt;Multiple workers can run simultaneously, allowing jobs to be processed in parallel.&lt;/li&gt;
&lt;li&gt;Queue backends (like Redis) act as middlemen to store jobs until workers pick them up.&lt;/li&gt;
&lt;li&gt;Tools like Supervisor ensure workers run continuously in production.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Laravel’s queue system is a smart way to handle tasks in the background, improving application performance and user experience. While PHP itself is single-threaded, Laravel achieves parallelism by running multiple processes (workers). This simple yet effective design allows Laravel to handle heavy workloads, even with PHP’s limitations.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Best Redis Caching Strategy in Laravel: A Guide to Fast and Efficient Caching</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Mon, 11 Nov 2024 07:40:44 +0000</pubDate>
      <link>https://dev.to/devmahfuz/best-redis-caching-strategy-in-laravel-a-guide-to-fast-and-efficient-caching-29e1</link>
      <guid>https://dev.to/devmahfuz/best-redis-caching-strategy-in-laravel-a-guide-to-fast-and-efficient-caching-29e1</guid>
      <description>&lt;p&gt;Laravel and Redis are a powerful combination for boosting application speed and performance. Redis, an in-memory key-value store, is perfect for caching, especially when you need fast and frequent data access. In this guide, we'll look at effective caching strategies in Laravel with Redis. We'll cover how to cache data, manage expiration times, and efficiently clear caches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use Redis Caching?&lt;/strong&gt;&lt;br&gt;
When you cache with Redis in Laravel, you're essentially saving data temporarily to reduce the time spent querying the database. Caching speeds up data retrieval, reduces server load, and improves user experience by making pages load faster.&lt;/p&gt;

&lt;p&gt;Redis is ideal for caching because it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can quickly store and retrieve data&lt;/li&gt;
&lt;li&gt;Supports various data structures like strings, lists, and hashes&lt;/li&gt;
&lt;li&gt;Offers tools for managing cache expiration and clearing old data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's explore how to best use Redis caching in Laravel.&lt;br&gt;
Let's say we have a News Paper Site. Now we need to build Api to Get News.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Setting Up Basic Caching with Laravel and Redis
&lt;/h2&gt;

&lt;p&gt;To start, let's cache a simple API response, like a list of the latest news articles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$data = Cache::remember('latest_news', 3600, function () {
    return News::latest()-&amp;gt;get();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;br&gt;
Cache::remember stores data with a key (latest_news) and a time-to-live (TTL) of 3600 seconds (1 hour).&lt;br&gt;
If a request for latest_news comes in again within the hour, Redis serves the cached data without querying the database.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Structuring Cache Keys and Expiration Times
&lt;/h2&gt;

&lt;p&gt;To keep the data fresh without overloading Redis:&lt;br&gt;
Set shorter TTLs for frequently updated data (e.g., 15–30 minutes).&lt;br&gt;
Use longer TTLs (e.g., 1–2 hours) for data that rarely changes.&lt;/p&gt;

&lt;p&gt;Use specific, structured cache keys that reflect the data content. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$cacheKey = "news:category:category_1";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This key is clear, unique, and self-descriptive, making it easy to identify and manage within Redis.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Using Tags for Grouped Cache Management
&lt;/h2&gt;

&lt;p&gt;Redis supports tags, which let us manage grouped data under a common tag. For example, tagging all news-related caches with news:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cache::tags(['news', 'category'])-&amp;gt;remember('category_news_1', 3600, function () {
    return $this-&amp;gt;news_repository-&amp;gt;getNewsByCategory(1);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if we want to clear all category-specific news caches (when news is updated), we can use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cache::tags(['news', 'category'])-&amp;gt;flush();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Caching Paginated and Filtered Data
When adding pagination or filters (like category or tags), make each cache key unique to the parameters:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$page = request()-&amp;gt;input('page', 1);
$limit = request()-&amp;gt;input('limit', 10);
$cacheKey = "news:page_{$page}:limit_{$limit}";

$newsData = Cache::remember($cacheKey, 3600, function () use ($page, $limit) {
    return News::latest()-&amp;gt;paginate($limit, ['*'], 'page', $page);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way:&lt;br&gt;
A unique cache entry is created for each page and limit.&lt;br&gt;
Users can fetch pages quickly without re-querying the database.&lt;/p&gt;

&lt;p&gt;For filtered data, include the filter parameters in the key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$categoryId = request()-&amp;gt;input('category_id');
$cacheKey = "news:category_{$categoryId}:page_{$page}:limit_{$limit}";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures each category and page combination has its own cache entry.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Automatic Cache Invalidation on Data Changes
&lt;/h2&gt;

&lt;p&gt;Clearing or "invalidating" caches ensures users see updated data when necessary. Here's how to automate it:&lt;br&gt;
Use model observers for events like created, updated, or deleted to clear related caches.&lt;br&gt;
Example observer for news:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function created(News $news) {
    Cache::tags(['news', 'pagination'])-&amp;gt;flush();
}

public function updated(News $news) {
    Cache::tags(['news', 'pagination'])-&amp;gt;flush();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, whenever news is added or updated, all news and pagination tagged caches are flushed, keeping the data fresh.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Summary and Best Practices
&lt;/h2&gt;

&lt;p&gt;To make caching work effectively:&lt;br&gt;
Unique Keys: Structure keys with parameters like category, page, and limit.&lt;br&gt;
Tags for Grouped Data: Use tags to easily manage caches for specific data groups.&lt;br&gt;
Automate Invalidation: Set up observers to clear outdated caches on data changes.&lt;br&gt;
Set Sensible Expiration: Choose TTLs based on how often the data changes, typically between 15 minutes and 1 hour.&lt;/p&gt;

&lt;p&gt;Using Redis with this structured approach makes Laravel APIs respond faster, improves server load management, and ensures a reliable, efficient cache strategy that's easy to manage.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>redis</category>
      <category>php</category>
      <category>database</category>
    </item>
    <item>
      <title>Where Does Deleted Data Go? Unveiling the Secrets of File Deletion and Overwriting</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Wed, 02 Oct 2024 14:51:41 +0000</pubDate>
      <link>https://dev.to/devmahfuz/where-does-deleted-data-go-unveiling-the-secrets-of-file-deletion-and-overwriting-5h3h</link>
      <guid>https://dev.to/devmahfuz/where-does-deleted-data-go-unveiling-the-secrets-of-file-deletion-and-overwriting-5h3h</guid>
      <description>&lt;p&gt;Ever wondered where the files go when you delete them from your computer or phone? Are they really gone or are they just playing an epic game of hide and seek behind those memory blocks, waiting to be recovered? I’ve got a burning curiosity and an urge to understand what actually happens at the lowest level when we delete a file. So, let’s embark on this journey of discovery… and hopefully, we’ll find out that the files aren’t just off on a tropical vacation!&lt;/p&gt;

&lt;p&gt;To understand what happens when a file is deleted and overwritten, and how the storage system handles data at a deeper level, we need to break down how files are stored and managed on a storage device. We’ll also dive into the physical aspects of how bits and bytes are written, erased, and overwritten, and explain why they don’t “pile up” or continue to occupy space after being overwritten.&lt;/p&gt;

&lt;p&gt;When you delete a file from your hard drive or SSD, the data isn't immediately erased. Instead, the system removes the file's reference and marks the storage space as available for reuse. On traditional hard drives (HDDs), the data remains as magnetic patterns until it's overwritten by new data. In solid-state drives (SSDs), a TRIM command marks the data for erasure, allowing faster overwriting. While deleted data can sometimes be recovered before it's overwritten, once new data replaces it, the old information is effectively lost. For secure deletion, special tools overwrite the data multiple times to ensure it cannot be restored. Understanding this process is crucial for managing storage and protecting sensitive information.&lt;/p&gt;

&lt;p&gt;You can read my details explanation from here - &lt;a href="https://medium.com/@mahfuz34/where-does-deleted-data-go-unveiling-the-secrets-of-file-deletion-and-overwriting-07c25482d706" rel="noopener noreferrer"&gt;My Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>memory</category>
      <category>filesystem</category>
      <category>programming</category>
    </item>
    <item>
      <title>Laravel `loadCount` Relationship Count 😎</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Tue, 26 Dec 2023 03:40:26 +0000</pubDate>
      <link>https://dev.to/devmahfuz/laravel-loadcount-relationship-count-boj</link>
      <guid>https://dev.to/devmahfuz/laravel-loadcount-relationship-count-boj</guid>
      <description>&lt;p&gt;Hello Artisans 😎&lt;/p&gt;

&lt;p&gt;Did you know you can get relationship counts even after retrieving the parent model? 🤔&lt;/p&gt;

&lt;p&gt;Using the loadCount method, you may load a relationship count after the parent model has already been retrieved:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$book = Book::first();

$book-&amp;gt;loadCount('genres');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need to set additional query constraints on the count query, you may pass an array keyed by the relationships you wish to count. The array values should be closures which receive the query builder instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$book-&amp;gt;loadCount(['reviews' =&amp;gt; function (Builder $query) {
    $query-&amp;gt;where('rating', 5);
}])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>webdev</category>
      <category>laraveltips</category>
    </item>
    <item>
      <title>How to use PHP within JavaScript on the Laravel framework.</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Tue, 14 Nov 2023 08:57:51 +0000</pubDate>
      <link>https://dev.to/devmahfuz/how-to-use-php-within-javascript-on-the-laravel-framework-36o8</link>
      <guid>https://dev.to/devmahfuz/how-to-use-php-within-javascript-on-the-laravel-framework-36o8</guid>
      <description>&lt;p&gt;Hey Laravel Devs 📢&lt;br&gt;
Do you know? You can use Laravel Blades&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ }}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in JS and use PHP variables in there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1l50m0yrymindqk6kkbi.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1l50m0yrymindqk6kkbi.jpeg" alt="Image description" width="655" height="261"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, You Can Use Route In Ajax URL&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0v6mk5uha7x0fux7pt3l.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0v6mk5uha7x0fux7pt3l.jpeg" alt="Image description" width="750" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But your JS must be in the Blade file inside the "script" tag.&lt;/p&gt;

&lt;h1&gt;
  
  
  Laravel #javascript
&lt;/h1&gt;

</description>
    </item>
    <item>
      <title>Dynamic Components In Vue</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Thu, 09 Nov 2023 04:35:52 +0000</pubDate>
      <link>https://dev.to/devmahfuz/dynamic-components-in-vue-1d87</link>
      <guid>https://dev.to/devmahfuz/dynamic-components-in-vue-1d87</guid>
      <description>&lt;p&gt;Dynamic components allow you to switch between different components based on a condition without using multiple conditional statements. To create a dynamic component, use the reserved  tag with the 'is' attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;component v-bind:is="currentComponent"&amp;gt;&amp;lt;/component&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your Vue.js instance, you can update the value of 'currentComponent' to switch between components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;new Vue({
  el: '#app',
  data: {
    currentComponent: 'component-a'
  },
  components: {
    'component-a': ComponentA,
    'component-b': ComponentB
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>vue</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Optimizing Vue Js Performance: Practical Tips and Code Examples Part 1</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Wed, 08 Nov 2023 08:51:27 +0000</pubDate>
      <link>https://dev.to/devmahfuz/optimizing-vue-js-performance-practical-tips-and-code-examples-part-1-5b14</link>
      <guid>https://dev.to/devmahfuz/optimizing-vue-js-performance-practical-tips-and-code-examples-part-1-5b14</guid>
      <description>&lt;p&gt;Performance optimization is crucial when developing Vue.js applications, especially as they grow in complexity. In this article, we will explore practical tips and code examples to help you squeeze the best performance out of your Vue.js projects.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use v-for with a Unique Key.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When rendering lists with v-for, ensure each item has a unique key. This allows Vue to efficiently track and update elements in the list, improving rendering performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9a7k5dhgs0jc5d9kn5p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9a7k5dhgs0jc5d9kn5p.png" alt="Image description" width="679" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Computed Properties&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use computed properties to cache and efficiently manage complex calculations or data transformations. This reduces redundant calculations and improves rendering performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F79xhi9hi4a429bcye4tg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F79xhi9hi4a429bcye4tg.png" alt="Image description" width="675" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keep Watchers and Listeners Minimal&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Avoid creating unnecessary watchers and event listeners, as they can lead to performance bottlenecks. Only watch or listen to changes that are critical for your component’s functionality.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0s5u3sd9v8bz07rwehu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0s5u3sd9v8bz07rwehu.png" alt="Image description" width="677" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I write on Medium Regularly. You can follow me for regular tips. &lt;a href="https://medium.com/@mahfuz34" rel="noopener noreferrer"&gt;https://medium.com/@mahfuz34&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vue</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Javascript Underrated Method "endsWith()"</title>
      <dc:creator>Mahfuzur Rahman</dc:creator>
      <pubDate>Mon, 06 Nov 2023 08:53:52 +0000</pubDate>
      <link>https://dev.to/devmahfuz/javascript-underrated-method-endswith-2jm8</link>
      <guid>https://dev.to/devmahfuz/javascript-underrated-method-endswith-2jm8</guid>
      <description>&lt;p&gt;The endsWith function is a method available in JavaScript for strings. It is used to check if a string ends with a specified substring, and it returns a Boolean value (true or false) based on the result of the check.&lt;/p&gt;

&lt;p&gt;Here's the basic syntax of the endsWith function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string.endsWith("searchString", length]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;string: The original string you want to check.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;searchString: The substring you want to check for at the end of the original string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;length (optional): The length of the string to consider. If provided, endsWith will check if the substring appears within the first length characters of the original string.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The function returns true if the original string ends with the specified substring, and false otherwise.&lt;/p&gt;

&lt;p&gt;Here are some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "Hello, world!";

console.log(str.endsWith("world"));  // true
console.log(str.endsWith("!"));      // true
console.log(str.endsWith("Hello"));   // false
console.log(str.endsWith("world", 7); // true (only considering the first 7 characters)

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

&lt;/div&gt;



&lt;p&gt;In the first example, the string "Hello, world!" ends with "world," so endsWith returns true.&lt;br&gt;
In the second example, it ends with "!" and returns true again.&lt;br&gt;
In the third example, it does not end with "Hello," so it returns false.&lt;br&gt;
The fourth example demonstrates the use of the optional length parameter, where we check if "world" appears within the first 7 characters of the string, which returns true.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
