development shits

Lately I've been dealing mainly with code instead of administration, so the dramas I face with coding are much more than server ones., so I decided to write a few lines about the nonsense I manage to create. We are preparing hard to present our project, which forces the opening of the dramatic parts to some extent

  • The first thing that would certainly cause problems is the exclusion of javascript from browser support. Like any modern application, our tool uses a lot of JS for AJAX and other dynamic processes that transmit interactivity and modernly improve vision and functionality. We thought of a lot of solutions and the most acceptable was with an information cookie and then php to check if the information is valid and if everything is OK. Quite a competent solution, but in the end it appeared in a decent way. HTML to run if it gets into noscript. In my opinion, it is the most elegant solution.
<meta http-equiv="refresh" content="0;URL=./nojs.html" />

In general, the situation is trivial if we stop JS support we will be redirected to nojs.html. A simple and quite effective solution

  • Php multhithreading – very filament is something that is quite useful with more core processors (not that single-core is not OK but with many nuclear systems things are different beer). Our software has a section that deals with gathering information from others API – that and me import you into our database. Generally no challenge except that we implemented it again in php with multhithreading in cli mode because this process is large enough and needs to be automated to force someone to do it by hand. There was a drama here related to the formation of processes and not the very creation of child process-and that the script was waiting to finish to create a new one. Stupidly this killed the idea of ​​multiprocessing what is actually behavior and not multhithreading but these are details. First we put & after the process, which means that the script continues to work, but still there was no change in the behavior, it was required that the standard output of the script be redirected. – in my case best to /dev/null 🙂 In the end, the structure of this piece of code looked like this
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
}else if ($pid) {
// we are the parent
echo "I'm parent  \n";
pcntl_wait($status); //Protect against Zombie children
} else {
// we are the child
echo "I'm a child $timer  \n";
exec("$command > /dev/null &");
exit (0);

The example is again trivial. In terms of performance, I was very impressed with the interruptions between lifting processes and so on 50 child process who made their side 7800+ mysql inserts for about 30-40 sec. And the machine is extremely weak because it is a test verer before we pick up the application of the real.

  • Mysql querys – I was shocked by a great stupidity. There was a code he was making 4-5 redundant database queries, instead of using a bolder sql query and then the main job is to take it to php. The drama was like that, the most- first a request was made which took information then the output of the request was used to make other requests as it served as arguments. Quite an ugly and fat situation. Subquery and it's unfamiliar territory obviously as well as left join or things just weren't well thought out. I caught rewriting the request everything went pretty well and overall the load dropped by about 200% for the same part of the code.

In general, these are the last things we deal with and I can't say that it's boring, but sometimes I am amazed by various ill-considered pieces of code that I have to fix and the most confusing thing is that they are often mine 😆

Enhanced by Zemanta


  1. И аз имам тегления на данни, сложени в crontab-a. Пробвах преди със & в края, но ставаше пиково натоварване, грозна история. Сега съм ги оставил, като свърши единия процес, да пуска другия, но това е ужасТ :> Като зацикли някъде и всичко отива по дяволитетова го решавам като килвам старите процеси, като дойде време да се пуска новия, но това е още по-голям ужасТ, защото губя данни. Та ще се се опитам да имплементирам, твоето решене по този въпрос. Благодарско! 🙂

    1. Ами по моя метод хубавото е че информацията може да се обработва от няколко процеса едновременно но това също ти гарантира по голямо натоварване 😉 Баланса между натоварване и скорост винаги е много тънък. Всичко опира до тестове.

Leave a Reply

Your email address will not be published.

Anti SPAM *