<?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 Rashid Khitilov on Medium]]></title>
        <description><![CDATA[Stories by Rashid Khitilov on Medium]]></description>
        <link>https://medium.com/@rashid.khitilov?source=rss-2f9aaabec831------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*R0qDJuCQQffeIPh3.</url>
            <title>Stories by Rashid Khitilov on Medium</title>
            <link>https://medium.com/@rashid.khitilov?source=rss-2f9aaabec831------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:08:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rashid.khitilov/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[Automatically archive old files in a Laravel application]]></title>
            <link>https://medium.com/@rashid.khitilov/automatically-archive-old-files-in-a-laravel-application-38354c0a7bfb?source=rss-2f9aaabec831------2</link>
            <guid isPermaLink="false">https://medium.com/p/38354c0a7bfb</guid>
            <dc:creator><![CDATA[Rashid Khitilov]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 20:27:00 GMT</pubDate>
            <atom:updated>2024-02-13T20:27:00.222Z</atom:updated>
            <content:encoded><![CDATA[<p>To automatically archive old files in a Laravel application, you can create a custom Artisan command that searches for and moves files older than a certain threshold to an archive directory. Here’s a step-by-step guide on how to achieve this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZV9VyIOAgDLfQvDXIr5Zbw.jpeg" /></figure><ol><li>Create a Custom Artisan Command:</li></ol><blockquote>Generate a new Artisan command using the make:command Artisan command: app/Console/Commands</blockquote><pre>php artisan make:command ArchiveFiles</pre><p>2. Implement the Command:</p><blockquote>Open the generated ArchiveFiles command class and implement the logic to search for and move old files to the archive directory. You can use Laravel&#39;s Filesystem component to interact with the filesystem.</blockquote><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use Illuminate\Console\Command;<br>use Illuminate\Support\Facades\File;<br><br>class ArchiveFiles extends Command<br>{<br>    protected $signature = &#39;archive:files&#39;;<br>    protected $description = &#39;Archive old files&#39;;<br><br>    public function handle()<br>    {<br>        $sourceDirectory = public_path(&#39;files&#39;); // Directory containing the files<br>        $archiveDirectory = public_path(&#39;archive&#39;); // Archive directory<br><br>        // Create the archive directory if it doesn&#39;t exist<br>        if (!File::isDirectory($archiveDirectory)) {<br>            File::makeDirectory($archiveDirectory);<br>        }<br><br>        // Move files older than 30 days to the archive directory<br>        $files = File::files($sourceDirectory);<br>        foreach ($files as $file) {<br>            if (File::lastModified($file) &lt; now()-&gt;subDays(30)) {<br>                File::move($file, $archiveDirectory . &#39;/&#39; . $file-&gt;getFilename());<br>            }<br>        }<br><br>        $this-&gt;info(&#39;Files archived successfully.&#39;);<br>    }<br>}</pre><p>3. Register the Command: app/Console/Kernel.php</p><pre>protected $commands = [<br>    // Other commands...<br>    Commands\ArchiveFiles::class,<br>];</pre><p>4. Schedule the Command:</p><blockquote>You can schedule the command to run automatically using Laravel’s task scheduler. Open the app/Console/Kernel.php file and define the schedule in the schedule method:</blockquote><pre>protected function schedule(Schedule $schedule)<br>{<br>    $schedule-&gt;command(&#39;archive:files&#39;)-&gt;daily();<br>}</pre><p>This will run the archive:files command daily. You can adjust the schedule as needed (e.g., hourly, weekly, etc.).</p><p>5. Run the Scheduler:</p><blockquote>Make sure that Laravel’s scheduler is running. You can do this by adding the following Cron entry to your server:</blockquote><pre>* * * * * php /path-to-your-project/artisan schedule:run &gt;&gt; /dev/null 2&gt;&amp;1</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38354c0a7bfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging in Laravel]]></title>
            <link>https://medium.com/@rashid.khitilov/logging-in-laravel-3f796478bde4?source=rss-2f9aaabec831------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f796478bde4</guid>
            <dc:creator><![CDATA[Rashid Khitilov]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 20:19:58 GMT</pubDate>
            <atom:updated>2024-02-13T20:19:58.059Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*dcqGMA0-wF5aA-0hj7Qs8w.png" /></figure><p>Logging in Laravel is flexible and allows for customization to suit your needs. You can log messages to different log files based on their context or severity. Here’s how you can achieve this with best practices:</p><ol><li>Configure Logging Channels:</li></ol><blockquote>Laravel provides logging channels in the config/logging.php file. You can define multiple channels, each with its own configuration. You can specify the log file path, log level, and other options for each channel.</blockquote><pre>&#39;channels&#39; =&gt; [<br>    &#39;stack&#39; =&gt; [<br>        &#39;driver&#39; =&gt; &#39;stack&#39;,<br>        &#39;channels&#39; =&gt; [&#39;daily&#39;, &#39;errors&#39;],<br>    ],<br><br>    &#39;daily&#39; =&gt; [<br>        &#39;driver&#39; =&gt; &#39;daily&#39;,<br>        &#39;path&#39; =&gt; storage_path(&#39;logs/app.log&#39;),<br>        &#39;level&#39; =&gt; &#39;debug&#39;,<br>        &#39;days&#39; =&gt; 7,<br>    ],<br><br>    &#39;errors&#39; =&gt; [<br>        &#39;driver&#39; =&gt; &#39;daily&#39;,<br>        &#39;path&#39; =&gt; storage_path(&#39;logs/errors.log&#39;),<br>        &#39;level&#39; =&gt; &#39;error&#39;,<br>        &#39;days&#39; =&gt; 7,<br>    ],<br>],</pre><blockquote>In this example, we have two channels: daily and errors. The daily channel logs all messages with the level debug or higher to storage/logs/app.log, while the errors channel logs messages with the level error or higher to storage/logs/errors.log.</blockquote><p>2. Use Different Log Methods:</p><blockquote>In your application code, you can use different logging methods provided by Laravel’s Log facade to log messages to the appropriate channel.</blockquote><pre>use Illuminate\Support\Facades\Log;<br><br>Log::channel(&#39;daily&#39;)-&gt;info(&#39;This is an info message logged to daily channel.&#39;);<br>Log::channel(&#39;errors&#39;)-&gt;error(&#39;This is an error message logged to errors channel.&#39;);<br><br>#You can also log messages within specific parts of your application. For example, you might want to log authentication-related messages to a separate log file.<br>Log::channel(&#39;auth&#39;)-&gt;info(&#39;User logged in.&#39;, [&#39;user_id&#39; =&gt; $user-&gt;id]);</pre><p>3. Consider Log Rotation:</p><p>To prevent log files from growing indefinitely, consider enabling log rotation. Laravel’s default daily log channel configuration includes log rotation, which rotates log files daily and keeps logs for a specified number of days (&#39;days&#39; =&gt; 7 in the example above). You can adjust the log rotation settings as needed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f796478bde4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel — Send emails to thousands people efficiently without causing your application]]></title>
            <link>https://medium.com/@rashid.khitilov/laravel-send-emails-to-thousands-people-efficiently-without-causing-your-application-7fa690f1439e?source=rss-2f9aaabec831------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fa690f1439e</guid>
            <dc:creator><![CDATA[Rashid Khitilov]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 20:13:42 GMT</pubDate>
            <atom:updated>2024-02-13T20:13:42.783Z</atom:updated>
            <content:encoded><![CDATA[<h3>Laravel — Send emails to thousands people efficiently without causing your application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YrxbHXCoQUZ62_6pWVSR9A.jpeg" /></figure><p>To send emails to 10,000 people efficiently without causing your application to wait for page reloading, you can utilize Laravel’s queue system to handle the task in the background. Additionally, you can chunk the email sending process to send emails in batches, ensuring smoother processing and avoiding performance issues.</p><ol><li>Set Up Email Queueing:</li></ol><blockquote>Ensure that your email configuration is set up correctly in Laravel’s .env file, and that you&#39;ve configured a queue connection as discussed earlier.</blockquote><p>2. Create an Email Sending Job:</p><blockquote>Generate a job using Artisan command: App/Jobs</blockquote><pre>php artisan make:job SendEmails</pre><p>3. Implement the Job:</p><p>Open the generated SendEmails job class and implement the handle() method. Within this method, you&#39;ll write the logic to send emails in batches.</p><pre>&lt;?php<br><br>namespace App\Jobs;<br><br>use App\Models\User;<br>use Illuminate\Bus\Queueable;<br>use Illuminate\Contracts\Queue\ShouldQueue;<br>use Illuminate\Foundation\Bus\Dispatchable;<br>use Illuminate\Queue\InteractsWithQueue;<br>use Illuminate\Queue\SerializesModels;<br>use Illuminate\Support\Facades\Mail;<br><br>class SendEmails implements ShouldQueue<br>{<br>    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;<br><br>    public function handle()<br>    {<br>        $users = User::all(); // Retrieve your users, adjust as needed<br><br>        $chunkedUsers = $users-&gt;chunk(100); // Split users into chunks of 100<br><br>        foreach ($chunkedUsers as $chunk) {<br>            foreach ($chunk as $user) {<br>                Mail::to($user-&gt;email)-&gt;send(new YourMailable($user)); // Send email using your Mailable<br>            }<br>        }<br>    }<br>}</pre><p>4. Dispatch the Job:</p><blockquote>Wherever you want to initiate the email sending process (e.g., in a controller method), dispatch the SendEmails job:</blockquote><pre>use App\Jobs\SendEmails;<br><br>public function sendEmails()<br>{<br>    SendEmails::dispatch();<br>}</pre><p>5. Run Your Queue Worker:</p><blockquote>Ensure that your queue worker is running to process the queued jobs in the background. Run the following command:</blockquote><pre>php artisan queue:work --queue=emails</pre><p>This command will start a queue worker specifically for processing email-related jobs.</p><p>By chunking the users and sending emails in batches, you can effectively manage the email sending process without overloading your application or causing delays for users. The queue worker will handle the job asynchronously, ensuring a smooth experience for users without waiting for page reloading. Adjust the chunk size and other parameters as needed based on your application’s requirements and constraints.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fa690f1439e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel-Implementing real-time notifications for users with ECHO server and Pusher]]></title>
            <link>https://medium.com/@rashid.khitilov/laravel-implementing-real-time-notifications-for-users-with-echo-server-and-pusher-bf7871c808c4?source=rss-2f9aaabec831------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf7871c808c4</guid>
            <dc:creator><![CDATA[Rashid Khitilov]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 20:01:27 GMT</pubDate>
            <atom:updated>2024-02-13T20:01:27.753Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ElBw1bdgQp31JeTV-TV-Kw.png" /></figure><ol><li>Install Laravel Echo and Pusher: First, install Laravel Echo and Pusher, which is a hosted service that provides the necessary infrastructure for real-time updates.</li></ol><pre>composer require pusher/pusher-php-server<br>npm install --save laravel-echo pusher-js</pre><p>2. Configure Pusher: Update your .env file with your Pusher credentials.</p><pre>BROADCAST_DRIVER=pusher<br><br>PUSHER_APP_ID=your-app-id<br>PUSHER_APP_KEY=your-app-key<br>PUSHER_APP_SECRET=your-app-secret<br>PUSHER_APP_CLUSTER=your-app-cluster</pre><p>3. Set Up Broadcasting: Enable broadcasting in your config/broadcasting.php file.</p><pre>&#39;connections&#39; =&gt; [<br>    &#39;pusher&#39; =&gt; [<br>        &#39;driver&#39; =&gt; &#39;pusher&#39;,<br>        &#39;key&#39; =&gt; env(&#39;PUSHER_APP_KEY&#39;),<br>        &#39;secret&#39; =&gt; env(&#39;PUSHER_APP_SECRET&#39;),<br>        &#39;app_id&#39; =&gt; env(&#39;PUSHER_APP_ID&#39;),<br>        &#39;options&#39; =&gt; [<br>            &#39;cluster&#39; =&gt; env(&#39;PUSHER_APP_CLUSTER&#39;),<br>            &#39;encrypted&#39; =&gt; true,<br>        ],<br>    ],<br>],</pre><p>4. Define Your Event: Create an event that represents your notification. For example, NotificationSent.</p><pre>&lt;?php<br><br>namespace App\Events;<br><br>use Illuminate\Broadcasting\Channel;<br>use Illuminate\Broadcasting\InteractsWithSockets;<br>use Illuminate\Broadcasting\PresenceChannel;<br>use Illuminate\Broadcasting\PrivateChannel;<br>use Illuminate\Contracts\Broadcasting\ShouldBroadcast;<br>use Illuminate\Foundation\Events\Dispatchable;<br>use Illuminate\Queue\SerializesModels;<br><br>class NotificationSent implements ShouldBroadcast<br>{<br>    use Dispatchable, InteractsWithSockets, SerializesModels;<br><br>    public $message;<br><br>    public function __construct($message)<br>    {<br>        $this-&gt;message = $message;<br>    }<br><br>    public function broadcastOn()<br>    {<br>        return new Channel(&#39;notifications&#39;);<br>    }<br>}</pre><p>5. Trigger the Event: Wherever you want to send a real-time notification, trigger the event.</p><pre>use App\Events\NotificationSent;<br><br>event(new NotificationSent(&#39;New notification!&#39;));</pre><p>6. Listening to the Event: On the client-side, use Laravel Echo to listen for the event.</p><pre>import Echo from &#39;laravel-echo&#39;<br><br>window.Echo = new Echo({<br>    broadcaster: &#39;pusher&#39;,<br>    key: process.env.MIX_PUSHER_APP_KEY,<br>    cluster: process.env.MIX_PUSHER_APP_CLUSTER,<br>    encrypted: true<br>});<br><br>window.Echo.channel(&#39;notifications&#39;)<br>    .listen(&#39;.App\\Events\\NotificationSent&#39;, (e) =&gt; {<br>        console.log(&#39;New notification:&#39;, e.message);<br>        // Handle the notification display<br>    });</pre><p>7. Display Notifications: Update your frontend code to display the notifications as desired.</p><p>That’s it! You now have real-time notifications set up in your Laravel application. Whenever you trigger the NotificationSent event, clients listening to the notifications channel will receive the notification in real time. Adjust the event and frontend code to suit your specific needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf7871c808c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Parameterized Queries or Prepared Statements in PHP?]]></title>
            <link>https://medium.com/@rashid.khitilov/how-to-use-parameterized-queries-or-prepared-statements-in-php-e20d9790bfd8?source=rss-2f9aaabec831------2</link>
            <guid isPermaLink="false">https://medium.com/p/e20d9790bfd8</guid>
            <dc:creator><![CDATA[Rashid Khitilov]]></dc:creator>
            <pubDate>Sat, 10 Feb 2024 14:10:35 GMT</pubDate>
            <atom:updated>2024-02-10T14:10:35.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qFgw4pOUcWcNh9kOt8xg9w.jpeg" /></figure><blockquote><strong>Example of using prepared statements with placeholders in PHP to prevent SQL injection</strong>:</blockquote><pre>// Establish a database connection (using PDO in this example)<br>$dsn = &#39;mysql:host=localhost;dbname=my_database&#39;;<br>$username = &#39;username&#39;;<br>$password = &#39;password&#39;;<br><br>try {<br>    $pdo = new PDO($dsn, $username, $password);<br>} catch (PDOException $e) {<br>    die(&quot;Connection failed: &quot; . $e-&gt;getMessage());<br>}<br><br>// User input (potentially vulnerable to SQL injection)<br>$userInput = $_POST[&#39;username&#39;];<br><br>// Prepare a SQL statement with a placeholder<br>$sql = &quot;SELECT * FROM users WHERE username = :username&quot;;<br><br>// Prepare the statement<br>$stmt = $pdo-&gt;prepare($sql);<br><br>// Bind the parameter to the placeholder<br>$stmt-&gt;bindParam(&#39;:username&#39;, $userInput, PDO::PARAM_STR);<br><br>// Execute the statement<br>$stmt-&gt;execute();<br><br>// Fetch the results<br>$results = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);<br><br>// Process the results (for example, output them)<br>foreach ($results as $row) {<br>    echo &quot;Username: &quot; . $row[&#39;username&#39;] . &quot;&lt;br&gt;&quot;;<br>    echo &quot;Email: &quot; . $row[&#39;email&#39;] . &quot;&lt;br&gt;&quot;;<br>    // Output additional user data as needed<br>}</pre><p>In this example:</p><ol><li>We establish a connection to the database using PDO.</li><li>We retrieve user input from $_POST[&#39;username&#39;]. This input could potentially be malicious and lead to SQL injection if not properly handled.</li><li>Instead of directly inserting the user input into the SQL query, we use a prepared statement with a placeholder (:username).</li><li>We bind the user input to the placeholder using bindParam() to ensure that it is treated as a parameter rather than part of the SQL query.</li><li>We execute the prepared statement using execute().</li><li>Finally, we fetch and process the results, ensuring that any data retrieved from the database is safe for output.</li></ol><blockquote>Let’s break down an example demonstrating the use of parameterized queries in PHP to prevent SQL injection:</blockquote><pre>// Establish a database connection (using PDO in this example)<br>$dsn = &#39;mysql:host=localhost;dbname=my_database&#39;;<br>$username = &#39;your_username&#39;;<br>$password = &#39;your_password&#39;;<br><br>try {<br>    $pdo = new PDO($dsn, $username, $password);<br>} catch (PDOException $e) {<br>    die(&quot;Connection failed: &quot; . $e-&gt;getMessage());<br>}<br><br>// User input (potentially vulnerable to SQL injection)<br>$userInput = $_POST[&#39;username&#39;];<br><br>// Prepare a SQL statement with placeholders<br>$sql = &quot;SELECT * FROM users WHERE username = ?&quot;;<br><br>// Prepare the statement<br>$stmt = $pdo-&gt;prepare($sql);<br><br>// Execute the statement with the user input as a parameter<br>$stmt-&gt;execute([$userInput]);<br><br>// Fetch the results<br>$results = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);<br><br>// Process the results (for example, output them)<br>foreach ($results as $row) {<br>    echo &quot;Username: &quot; . $row[&#39;username&#39;] . &quot;&lt;br&gt;&quot;;<br>    echo &quot;Email: &quot; . $row[&#39;email&#39;] . &quot;&lt;br&gt;&quot;;<br>    // Output additional user data as needed<br>}</pre><p>In this example:</p><ol><li>We establish a connection to the database using PDO, which is a PHP extension for interacting with databases in a secure and efficient manner.</li><li>We retrieve user input from $_POST[&#39;username&#39;]. This input could potentially be manipulated to perform SQL injection if not handled properly.</li><li>Instead of directly inserting the user input into the SQL query, we use a prepared statement with a placeholder (?). This placeholder represents a parameter that will be replaced with the actual value during execution.</li><li>We prepare the SQL statement using the prepare() method of the PDO object.</li><li>We execute the prepared statement using the execute() method, passing the user input as an array of parameters. PDO automatically handles the escaping and quoting of values, preventing SQL injection.</li><li>We fetch and process the results, ensuring that any data retrieved from the database is safe for output.</li></ol><p>Using parameterized queries is a robust method for preventing SQL injection in PHP applications. It separates the SQL logic from the user input, ensuring that malicious input cannot alter the structure of the query. Additionally, PDO handles the escaping and quoting of values automatically, further mitigating the risk of SQL injection.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e20d9790bfd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>