{
  "slug": "PHP-fpm---I-hate-you-1d17bb8a577b",
  "title": "PHP-fpm ! I hate you",
  "subtitle": "I have been a PHP developer for many years. Employers want to build every platform with PHP!",
  "excerpt": "I have been a PHP developer for many years. Employers want to build every platform with PHP!",
  "date": "2021-01-11",
  "tags": [
    "My Experience",
    "PHP",
    "Machine Learning"
  ],
  "readingTime": "2 min",
  "url": "https://medium.com/@mobinshaterian/php-fpm-i-hate-you-1d17bb8a577b",
  "hero": "https://cdn-images-1.medium.com/max/800/1*mt5x80RlRyTLz7iS5aVfTg.png",
  "content": [
    {
      "type": "heading",
      "level": 2,
      "text": "Effect of index column on Mysql performance"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*mt5x80RlRyTLz7iS5aVfTg.png",
      "alt": "problem with Mysql",
      "caption": "problem with Mysql",
      "width": 892,
      "height": 276
    },
    {
      "type": "paragraph",
      "html": "TIPS: I changing the title of an article from “PHP-fpm&nbsp;! I hate you” to “Effect of index column on Mysql performance” but some guys still watching previous title"
    },
    {
      "type": "paragraph",
      "html": "I have been a PHP developer for many years. Employers want to build every platform with PHP!"
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Dear Employer, please stop build everything with PHP + Mysql."
    },
    {
      "type": "paragraph",
      "html": "PHP has a huge community around the world and many developers build their websites with PHP. some framework such as Laravel very nice and big and working with these frameworks is very comfortable."
    },
    {
      "type": "paragraph",
      "html": "WordPress is one of the big CMS of PHP, many developers and Employers love these CMS because they can build their website only in one day!"
    },
    {
      "type": "paragraph",
      "html": "As example Ferraris vs. Jeeps both types are good and useful, in different situations. not using Ferraris for off-road usage."
    },
    {
      "type": "heading",
      "level": 2,
      "text": "This project different from the normal website"
    },
    {
      "type": "paragraph",
      "html": "in this project, we have a pipeline for the AI process. I’m huge recommend using some technology such as Airflow to don’t face MySQL problems."
    },
    {
      "type": "heading",
      "level": 2,
      "text": "why index column on Mysql is important?"
    },
    {
      "type": "paragraph",
      "html": "how many customers our clients will visit your website? this is the big question.<br>for example, we want to build a physical store in the city. many stores are tiny store upside of home and some store is Mega Market and they are huge."
    },
    {
      "type": "paragraph",
      "html": "WordPress is a common store and it looks like a small Store. when a website visits only 100 users in a day, WordPress is best and cheapest solution."
    },
    {
      "type": "paragraph",
      "html": "On other hand, Laravel is working with 100 users per second very well. but suddenly increase the number of clients we forced with 504 gateway error our website working very slow because of PHP-fpm Architecture."
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*sog1JKO3sZDHxtGHYmbapg.png",
      "alt": "504 Gateway Error",
      "caption": "504 Gateway Error",
      "width": 644,
      "height": 262
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Spending a Long Time to Handle 504 Gateway Error"
    },
    {
      "type": "paragraph",
      "html": "if the business decided to develop a web service with PHP technology and meet a long number of user support and maintenance the PHP web service is very painful."
    },
    {
      "type": "heading",
      "level": 2,
      "text": "in this problem Mysql can’t response fast to queries"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*k3H4rvlNdCHi0zeEWBKz6A.png",
      "alt": "response time",
      "caption": "response time",
      "width": 598,
      "height": 36
    },
    {
      "type": "paragraph",
      "html": "when I write simple query such as"
    },
    {
      "type": "code",
      "lang": "sql",
      "code": "SELECT *\nFROM `tables`\nWHERE `status_id` = 6"
    },
    {
      "type": "paragraph",
      "html": "mysql response"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*eylY2H6jYcBM9y3tNX6NGg.png",
      "alt": "PHP-fpm ! I hate you",
      "caption": "",
      "width": 567,
      "height": 32
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Caching"
    },
    {
      "type": "paragraph",
      "html": "Actually, in this problem, we have to deal with lots of computational tasks and it is not easy to use caching for machine learning. I<a href=\"https://mobinshaterian.medium.com/improve-speed-of-machine-learning-api-engine-from-3-requests-per-second-to-10000-requests-per-4d649d246a99\" target=\"_blank\" rel=\"noreferrer noopener\">n another problem, I use caching for Machine learning states with Redis</a> but in this case, using caching for machine learning is a very difficult thing."
    },
    {
      "type": "heading",
      "level": 2,
      "text": "How we solve the problem"
    },
    {
      "type": "paragraph",
      "html": "At first, we increase the number of CPUs and the size of the ram of the server. Secondly optimization query and add an index The most used column."
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*TZlGsqnBtuCBAY7Fftjphw.png",
      "alt": "ctop contianer usage",
      "caption": "ctop contianer usage",
      "width": 649,
      "height": 322
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*hiisXJlWItyd_suTvleqog.png",
      "alt": "htop cpu usage",
      "caption": "htop cpu usage",
      "width": 1176,
      "height": 205
    },
    {
      "type": "code",
      "lang": "sql",
      "code": "SELECT *\nFROM `tables`\nWHERE `status_id` = 6"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*yMFoP1etPu_NZUvc-1ROIg.png",
      "alt": "after optimization query and index",
      "caption": "after optimization query and index",
      "width": 593,
      "height": 32
    }
  ]
}