<?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: Peham Raza</title>
    <description>The latest articles on DEV Community by Peham Raza (@peham).</description>
    <link>https://dev.to/peham</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%2F662653%2F7800383f-24f3-4cc4-87c5-515aaec2b725.jpg</url>
      <title>DEV Community: Peham Raza</title>
      <link>https://dev.to/peham</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/peham"/>
    <language>en</language>
    <item>
      <title>Pro Tips: How to avoid database deadlocks when working with CRON jobs</title>
      <dc:creator>Peham Raza</dc:creator>
      <pubDate>Tue, 13 Sep 2022 17:31:42 +0000</pubDate>
      <link>https://dev.to/peham/pro-tips-how-to-avoid-database-deadlocks-when-working-with-cron-jobs-3j65</link>
      <guid>https://dev.to/peham/pro-tips-how-to-avoid-database-deadlocks-when-working-with-cron-jobs-3j65</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Database overloading for a large/ commercial system that has a complicated database and too many CRON jobs. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tech stack in focus:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;PHP&lt;/li&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;Apache2&lt;/li&gt;
&lt;li&gt;CRON jobs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mistakes you make when designing a system that costs you a lot in future&lt;/p&gt;

&lt;p&gt;Some minor mistakes you make when designing a large scale application that cost you a lot and could have been fixed by avoiding a few mistakes include,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Designing a database without Foreign keys&lt;/li&gt;
&lt;li&gt;Choosing wrong data types and their sizes&lt;/li&gt;
&lt;li&gt;Using too many TEXT fields&lt;/li&gt;
&lt;li&gt;Database with duplicated data across multiple tables&lt;/li&gt;
&lt;li&gt;Not using indexes&lt;/li&gt;
&lt;li&gt;Too many joins&lt;/li&gt;
&lt;li&gt;Updating a single column over and over again to keep track of system updates&lt;/li&gt;
&lt;li&gt;Too many queries to file system&lt;/li&gt;
&lt;li&gt;Not setting up a mechanism for getting rid of old unused data&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Avoiding the mistakes/ database deadlocks
&lt;/h2&gt;

&lt;p&gt;When we have scheduled tasks and are planning to design a system where we are periodically updating stats, working with the Apache server with PHP in MySQL, instead of using update queries for rows or columns you want to periodically update, try to use insert queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Designing a database without Foreign keys
&lt;/h2&gt;

&lt;p&gt;The best advice i can give you is to just not rush the step of designing a database. Either you are on a short deadlines or you are being just too careless about this step, its going to cost you major $$$ and time in future.&lt;/p&gt;

&lt;p&gt;Take your time, think things through, use dependencies and make your data consistent.&lt;/p&gt;

&lt;p&gt;Use Foreign keys everywhere! If you think about the pain it gives you putting them in thinking them through or you just avoid them because of the deletion errors you face when removing data, think again.&lt;/p&gt;

&lt;p&gt;If you do the Foreign keys properly the deletion becomes easy and there would be almost no unrelated data when removing a top level database record.&lt;/p&gt;

&lt;p&gt;It also protects you from removing a record in a parent table that has child records.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Choosing wrong data types and their sizes
&lt;/h2&gt;

&lt;p&gt;The rule here is to don’t over do them.&lt;/p&gt;

&lt;p&gt;The max allowed values are the ones you would decide on application level, not the ones the user “CAN” put it. Remember you can always do validation on the application side.&lt;/p&gt;

&lt;p&gt;Not all records have the max values put it in so don’t overdo them.&lt;/p&gt;

&lt;p&gt;Using unsigned values for auto increment columns and values that may never be negative is another good example.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Using too many TEXT fields
&lt;/h2&gt;

&lt;p&gt;TEXT fields are slower, varchar is better. Use TEXT only when the text is going to be really long.&lt;/p&gt;

&lt;p&gt;TEXT fields can be part of an index upto a specific length, varchars are better option here too.&lt;/p&gt;

&lt;p&gt;Too many TEXT column in a record would make fetching your data slower.&lt;/p&gt;

&lt;p&gt;Read complete article on &lt;a href="https://peham.dev/tips/avoid-deadlocks-when-working-with-cron-jobs/" rel="noopener noreferrer"&gt;my BLOG&lt;/a&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>mysql</category>
      <category>webdev</category>
      <category>design</category>
    </item>
    <item>
      <title>Getting impatient? Know that:</title>
      <dc:creator>Peham Raza</dc:creator>
      <pubDate>Fri, 12 Aug 2022 11:13:04 +0000</pubDate>
      <link>https://dev.to/peham/getting-impatient-know-that-17cp</link>
      <guid>https://dev.to/peham/getting-impatient-know-that-17cp</guid>
      <description>&lt;p&gt;👉 The shortest path is not always the easiest or quickest.&lt;br&gt;
👉 You can never know if the path you have chosen is the one to make you successful.&lt;br&gt;
👉 Do your best, control what you can and leave the rest to God/ fate.&lt;br&gt;
👉 Keep your mind open to learning new lessons, accept that you can be wrong, so you may improve.&lt;/p&gt;

&lt;p&gt;Have patience. It will happen!&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Lesson learned the hard way</title>
      <dc:creator>Peham Raza</dc:creator>
      <pubDate>Wed, 10 Aug 2022 03:49:58 +0000</pubDate>
      <link>https://dev.to/peham/lesson-learned-the-hard-way-2ahd</link>
      <guid>https://dev.to/peham/lesson-learned-the-hard-way-2ahd</guid>
      <description>&lt;p&gt;The best advice for a #developer working on something that is taking longer than expected is to be honest and communicate it clearly.&lt;br&gt;
Taking responsibility and letting stakeholders know that you need more time is always better than avoiding them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://peham.dev" rel="noopener noreferrer"&gt;https://peham.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>programming</category>
      <category>webdev</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>The joy of things that are unmatched</title>
      <dc:creator>Peham Raza</dc:creator>
      <pubDate>Fri, 05 Aug 2022 11:35:25 +0000</pubDate>
      <link>https://dev.to/peham/the-joy-of-things-that-are-unmatched-5cie</link>
      <guid>https://dev.to/peham/the-joy-of-things-that-are-unmatched-5cie</guid>
      <description>&lt;p&gt;👉 Creating something useful&lt;br&gt;
👉 Completing a project and watching it go live&lt;br&gt;
👉 Recieving positive feedback for your hardwork&lt;br&gt;
👉 Your product is enabling people to grow and pay their bills&lt;br&gt;
👉 Seeing yourself achieve goals that you never knew you could&lt;/p&gt;

&lt;p&gt;Stay humble and enjoy the journey while you are here!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>softwaredevelopment</category>
      <category>motivation</category>
    </item>
    <item>
      <title>PHP multi threads - Setup PHP7.2 cli with pthreads</title>
      <dc:creator>Peham Raza</dc:creator>
      <pubDate>Mon, 30 May 2022 11:27:54 +0000</pubDate>
      <link>https://dev.to/peham/php-multi-threads-setup-php72-cli-with-pthreads-44g6</link>
      <guid>https://dev.to/peham/php-multi-threads-setup-php72-cli-with-pthreads-44g6</guid>
      <description>&lt;p&gt;&lt;a href="https://peham.dev/devops/php-with-multiple-threads/" rel="noopener noreferrer"&gt;PHP multi threads - Setup PHP 7.2cli with Multiple Threads (pthreads) on Ubuntu&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article I'm going to write steps required to setup PHP multi threads on your server.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Why PHP multi threads - CLI Version: *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Running app on PHP 5.6 for web app but need PHP7.2 (pthreads) with multiple threads to run tasks at background so we can run multiple independent business logics without interfering with main web app.&lt;/p&gt;

&lt;p&gt;﻿&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install required libraries&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install libc-client-dev libkrb5-dev libgmp-dev apache2-dev libzip-dev bison autoconf build-essential pkg-config git-core libltdl-dev libbz2-dev libxml2-dev libxslt1-dev libssl-dev libicu-dev libpspell-dev libenchant-dev libmcrypt-dev libpng-dev libjpeg8-dev libfreetype6-dev libmysqlclient-dev libreadline-dev libcurl4-openssl-dev
sudo ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;﻿&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download &amp;amp; Build  PHP&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://github.com/php/php-src/archive/php-7.2.19.tar.gz
tar --extract --gzip --file php-7.2.19.tar.gz
cd php-src-php-7.2.19
./buildconf --force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;﻿&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CONFIGURE_STRING="--prefix=/etc/php7 --with-bz2 --with-zlib --enable-zip --disable-cgi \
--with-apxs2=/usr/bin/apxs2 --with-gmp --with-imap \ 
--enable-soap --enable-intl --with-openssl --with-readline --with-curl --enable-ftp \
--enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-sockets \
--enable-pcntl --with-pspell --with-enchant --with-gettext --with-gd --enable-exif \
--with-jpeg-dir --with-png-dir --with-freetype-dir --with-xsl --enable-bcmath \
--enable-mbstring --enable-calendar --enable-simplexml --enable-json --enable-hash \
--enable-session --enable-xml --enable-wddx --enable-opcache --with-pcre-regex \
--with-config-file-path=/etc/php7/cli --with-config-file-scan-dir=/etc/php7/etc \
--enable-cli --enable-debug --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data \
--with-mcrypt --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop \
--enable-pthreads --with-tsrm-pthreads --enable-maintainer-zts"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;﻿&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./configure $CONFIGURE_STRING
&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;make &amp;amp;&amp;amp; sudo make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;﻿&lt;/p&gt;

&lt;p&gt;Check it's installed (this should print 1)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/etc/php7/bin/php -r "echo PHP_ZTS;"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read remaining steps on &lt;a href="https://peham.dev/devops/php-with-multiple-threads/" rel="noopener noreferrer"&gt;peham.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>php7</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
