<?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: shirish rai</title>
    <description>The latest articles on DEV Community by shirish rai (@silverfox).</description>
    <link>https://dev.to/silverfox</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%2F3074698%2F79cde7d8-aaf4-4978-bfdf-a822d01585d5.jpg</url>
      <title>DEV Community: shirish rai</title>
      <link>https://dev.to/silverfox</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/silverfox"/>
    <language>en</language>
    <item>
      <title>Composer Install or Update? Best Practices for Safely Updating Composer in Production</title>
      <dc:creator>shirish rai</dc:creator>
      <pubDate>Wed, 27 Aug 2025 19:18:33 +0000</pubDate>
      <link>https://dev.to/silverfox/composer-install-or-update-best-practices-for-safely-updating-composer-in-production-1eg8</link>
      <guid>https://dev.to/silverfox/composer-install-or-update-best-practices-for-safely-updating-composer-in-production-1eg8</guid>
      <description>&lt;p&gt;When managing PHP applications &lt;strong&gt;especially in production&lt;/strong&gt; Composer can be both a lifesaver and a potential pitfall. Used carelessly, it can introduce bugs or even bring your app down. This post walks you through how to safely update Composer dependencies, explains why &lt;strong&gt;&lt;code&gt;composer update&lt;/code&gt;&lt;/strong&gt; should never be used on production, and outlines the right way to manage frequent package upgrades.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;🚫 Drawbacks of Running &lt;code&gt;composer update&lt;/code&gt; on Production&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;One of the biggest mistakes developers make is running &lt;strong&gt;&lt;code&gt;composer update&lt;/code&gt;&lt;/strong&gt; directly on a production server. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s why this is dangerous:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It updates all packages to the latest versions permitted by &lt;em&gt;composer.json&lt;/em&gt;, potentially introducing breaking changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It modifies both &lt;em&gt;composer.json&lt;/em&gt; and &lt;em&gt;composer.lock&lt;/em&gt;, which can cause your production environment to become out of sync.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There’s a risk of app downtime, as new versions may cause HTTP 500 errors or other critical failures.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The install process is &lt;strong&gt;resource-intensive&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the update fails midway, you could be left with a broken or inconsistent dependency state.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Other risks include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Unintended package upgrades.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lack of staging environment testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Skipping the standard &lt;strong&gt;CI/CD pipeline&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Possible download from &lt;strong&gt;untrusted sources&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;✅ The Correct Approach: Use &lt;code&gt;composer install&lt;/code&gt; on Production&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When deploying code to production, always use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer install --no-dev --optimize-autoloader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command ensures a clean, performant, and safe deployment. &lt;br&gt;
Let’s break down why these flags matter:&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;🔍 Why &lt;code&gt;--no-dev&lt;/code&gt; Is Critical&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;--no-dev&lt;/code&gt;&lt;/strong&gt; flag tells Composer to skip installing packages listed under the &lt;strong&gt;&lt;code&gt;require-dev&lt;/code&gt;&lt;/strong&gt; section of composer.json. These are typically tools used only during development and testing.&lt;/p&gt;

&lt;p&gt;Why it's important in production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Avoids exposing unnecessary tools that could pose a security risk.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduces disk space and speeds up deployment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensures a lean, minimal footprint optimized for production performance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;🚀 Why &lt;code&gt;--optimize-autoloader&lt;/code&gt; Matters&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Composer's autoloader can be optimized to improve performance by converting PSR-4/PSR-0 mappings into a class map. When you use &lt;strong&gt;&lt;code&gt;--optimize-autoloader&lt;/code&gt;&lt;/strong&gt;, it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Pre-generates a class map of all classes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduces filesystem lookups at runtime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improves request performance&lt;/strong&gt; and boot time, especially for larger apps.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;📦 Safely Updating a Specific Package&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Sometimes you might need to update a frequently patched package, like aws/aws-sdk-php. In that case, follow this safer approach:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-Step Guide&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;1&amp;gt; Create a new branch from master:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b update-aws-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2&amp;gt; Run the update command locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer update aws/aws-sdk-php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only update the specified package.&lt;/li&gt;
&lt;li&gt;Respect version constraints in your composer.json.&lt;/li&gt;
&lt;li&gt;Avoid touching unrelated dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3&amp;gt; Test thoroughly in your local or staging environment.&lt;br&gt;
4&amp;gt; Commit and merge the changes back to master.&lt;br&gt;
5&amp;gt; Deploy the updated branch to production.&lt;br&gt;
6&amp;gt; On the production server, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer install --no-dev --optimize-autoloader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;🧪 Reminder: Keep All Composer Updates in Source Control&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;All version upgrades should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be performed locally or in a &lt;strong&gt;CI/CD pipeline&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Be committed to source control.&lt;/li&gt;
&lt;li&gt;Go through a proper deployment workflow.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Never originate from the production server.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>laravel</category>
      <category>php</category>
      <category>devops</category>
    </item>
    <item>
      <title>Restarting Laravel Queue Workers Safely</title>
      <dc:creator>shirish rai</dc:creator>
      <pubDate>Tue, 06 May 2025 18:57:30 +0000</pubDate>
      <link>https://dev.to/silverfox/restarting-laravel-queue-workers-safely-306d</link>
      <guid>https://dev.to/silverfox/restarting-laravel-queue-workers-safely-306d</guid>
      <description>&lt;p&gt;When managing background processes or queue workers in a production environment, &lt;strong&gt;Supervisor&lt;/strong&gt; is often the go-to process control system. But if you’ve ever worked with Supervisor on a Linux server, you've likely come across these two commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service supervisor restart
sudo supervisorctl restart [program_name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They might look similar at a glance — both contain the word restart — but they operate at &lt;strong&gt;very different levels&lt;/strong&gt; and are used in &lt;strong&gt;very different situations&lt;/strong&gt;. Let’s break down what each command does, when to use it, and what to avoid in a production environment.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;🔍 1. sudo service supervisor restart&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;✅ What it does&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This command restarts the &lt;strong&gt;Supervisor daemon itself&lt;/strong&gt; — not just the programs it manages. Think of it as turning Supervisor completely off and then back on.&lt;/p&gt;

&lt;p&gt;When you run this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Supervisor stops all processes it’s managing.&lt;/li&gt;
&lt;li&gt;It re-reads your main config file (/etc/supervisor/supervisord.conf) and any included .conf files.&lt;/li&gt;
&lt;li&gt;Then it restarts itself and everything it controls.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;⚠️ Why it can be risky&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This method is &lt;strong&gt;disruptive&lt;/strong&gt;, especially in production environments. All processes — queue workers, background services, long-running jobs — are stopped and restarted. If any job is mid-processing, it could be lost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ When to use it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You've made changes to &lt;strong&gt;Supervisor's configuration files&lt;/strong&gt; and need them to take effect.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Supervisor daemon is &lt;strong&gt;unresponsive&lt;/strong&gt; or has crashed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want to &lt;strong&gt;restart all&lt;/strong&gt; managed processes at once and you're okay with downtime.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🧠 Pro Tip&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use this during scheduled maintenance windows or in development/staging environments.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;🔍 2. sudo supervisorctl restart [program_name]&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;✅ What it does&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This command is much more targeted. It allows you to restart &lt;strong&gt;a single program&lt;/strong&gt; without restarting the entire Supervisor service.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo supervisorctl restart laravel-worker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This stops just the laravel-worker process and starts it again — leaving other services untouched.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Why it's safer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because it doesn’t restart the Supervisor daemon itself, this command is &lt;strong&gt;less disruptive&lt;/strong&gt; and far more appropriate for &lt;strong&gt;production use&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can also use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo supervisorctl restart all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To restart all managed processes, &lt;strong&gt;without restarting Supervisor itself&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ When to use it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You’ve updated your application code (like deploying a new Laravel version).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want to restart just one service/worker.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want to minimize disruption while keeping services running.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;🔃 3. php artisan queue:restart&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;✅ What it does&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Gracefully tells Laravel to &lt;strong&gt;stop and restart all queue workers&lt;/strong&gt;, by updating a timestamp in the cache. Running workers detect this and &lt;strong&gt;shut themselves down after finishing their current job&lt;/strong&gt;.&lt;br&gt;
This command does &lt;strong&gt;not&lt;/strong&gt; stop the underlying process — Supervisor or another process monitor will automatically restart the worker afterward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📦 How it works&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Laravel stores a timestamp (in the cache) for the last restart request.&lt;/li&gt;
&lt;li&gt;Each worker checks this before picking up a new job.&lt;/li&gt;
&lt;li&gt;If the cache timestamp is newer than when the worker started, it exits.&lt;/li&gt;
&lt;li&gt;Supervisor (or systemd) sees that it exited and starts a new one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅ Why it’s safe and graceful&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It &lt;strong&gt;allows in-progress jobs to finish before shutting down&lt;/strong&gt;, preventing job loss or data corruption.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ When to use it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;During deployment after code changes&lt;/li&gt;
&lt;li&gt;When updating environment variables or job logic&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;🧠 Example Deployment Snippet&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If you're using Laravel queues (and you should be using Supervisor to manage them), it's best to restart your workers using Supervisor commands rather than manually killing and starting workers.&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:restart
sudo supervisorctl restart laravel-worker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This combo ensures Laravel gracefully restarts workers, and Supervisor brings them back up cleanly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔚 Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both sudo service supervisor restart and sudo supervisorctl restart are valuable tools — but like any powerful tool, &lt;strong&gt;use them wisely&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use supervisorctl restart [program_name] for safe, minimal-disruption restarts.&lt;/li&gt;
&lt;li&gt;Use service supervisor restart when you're updating Supervisor itself or 
fixing a broader issue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding the difference can help you avoid unintentional downtime and keep your production services running smoothly.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>devops</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
