My first plugin on Redirect to welcome or landing page

WordPress Plugins

WordPress is a great, flexible and powerful  CMS from my point of view it is the best and i see it is not only me as wordpress powers 23% of the internet, Plugins have a big hand of that powerfulness that wordpress have.

I have used and created plugins for many years now but the strange thing i have not try to publish any of them on the official store of ! not even my latest plugins WordPress static social sharing icons that i developed and use also in this site to speed up the page loading time !!

Today after two days in review i have got the “Request Approved” Email form on my plugin “Redirect to welcome or landing page“, its now live on and you can find it if you searched for “Redirect to welcome or landing page” in your plugins section in your website.

The plugin is easy, simple to the point plugin allow you to set page so users get redirected to it if they landed on your home page or any page or post. It is as simple as that whenever you get new visitor to your home page you may like to redirect him to a welcome o landing page that you promote your work in or give him some offer or ask for his email to join your newsletter.

The plugin have many use cases and a lot great bloggers have used the same concept to get more leads to there news letter of to spotlight there latest work and you to can get the advantage of it by going now to your plugins section in your wordpress site and searched for “Redirect to welcome or landing page”.

The plugin use temp redirection code so search engine will not lose track of your home page content.

Waiting all your feedback, one last time the link is “Redirect to welcome or landing page“.

How to force the client’s browser to clear cache files

keep calm and clear cache

I will write more technical posts on this blog but it will be in English, today’s post will be about common problem when you develop web application depend a lot on JavaScript or changes in design when you release its.

The problem:
You released new version from your site with changes in JavaScript and CSS but the users did not got that changes because the browser cached those files.

The solution:
Add suffix to all JavaScript and CSS files with release date in time stamp format like

<link href="css/main.css?1422439996" rel="stylesheet">

With the considerations that most if not all modern frameworks loads the JavaScript and CSS automatically from single function that you can alter to append the release date time stamp and recommended to read it from config file as it may be part from installation steps.

You have the file main.CSS in your web page and have been cached before when the user visited your web page so when you update the file content the browser will check only on the file name and it not be changed so will use the old cached file.
But when you add the release date as suffix when the user visit your page after the release date the browser will detect new file name so will load it and then cache it till the next release.

Whats next?
The next this is to go and talk with your team on how can you deploy this, if you needed farther details you can contact me directly or in the comments section. Don’t forget the most important thing subscribe to my news letter to get the upcoming posts directly in your mailbox and share this article to help others.

Does your Ajax requests take long time? it’s PHP session locking problem – updated

logo php sessionHello All,

That is the 9th\10th post in my challenge for 30 days of blogging and this post have been delayed because i was insisting on writing it in Arabic and its a technical post trying to document a technical solution for Ajax requests that take long time, That problem when i started on the blog post in Arabic i found difficulty in describing it and the solution with the right words so here it is in English.

The article require understanding of PHP Sessions and Ajax i will incloud definitions of them to make it easy for the ones who starting in PHP.

What is PHP session ?

Imagine you are developing a web application and want to recognize the user and remember who he is in all the pages without making him enter his details in every one, you may use Cookies or Session.

You get the point now Session is a way of storing users info and can recall it from any page, unlike Cookies Session stored on the server so user have no way of editing it.

By default session variables last until the user closes the browser or stay inactive for sometime defined in the server configurations, Whenever you want to recall or store user data in PHP page you must start the page with calling session_start() function so you know will have access on $_SESSION variable.

What is AJAX?

AJAX stands for Asynchronous JavaScript and XML. Is the way of sending and receiving data from a server without reloading the full page.

We use that method to send data and retrieve info from the server in faster way as we don’t want to receive the full page and render it in the browser as it will be much slower.

As result we can update part from the web page user on like what users see when they scroll down in facebook time line page as new content get added without refreshing the page.

The problem

We now -and it is not a new thing- develop applications depend on Ajax up to %100 But when a web page sends two or more Ajax requests you find them take mush time and maybe finish almost in the same time.

The cause

When you send an Ajax request to a server and your PHP script starts with


then that call and lock the PHP session file on the server and as you know PHP store sessions in files on server, so the same script can not edit the same session file on the server, and that is a classic lock file condition, so any other request will call PHP file that call session_start() will wait till the first request finish to start first in first out and now most if not all PHP frameworks use session_start() as first thing in the main file.

The solution


Using session_write_close() function to write and close the session file on the server will release the session file so another request can use it and this script will continue working normally but you should know that you are not allow to store any thing in the session after using session_write_close(); in the same script but from the other request it will be ok.


I have created a test code to see the problem ad uploaded it on GitHub you can find it here ” PHP session locking problem with Ajax” you will need to add it under your local host and open the console to see the requests  and responses time.

As we see in the code in that file, for example if we made more than request the a page have that code


Each request will wait the previous one to finish which will take 5 sec, because the session file have not be released yet so the new connected will be blocked on the first like session_start() that will kill the idea if asynchronous requests (more than one request can be send and executed in the same time).

If we changed the code to be like in that file


the second line in that code release the session file so the other requests now can start executing as they can call session_start() without any problems.

Happy coding :) till the next post remember to subscribe to the blog RSS feed and follow me on twitter.

Image source:

متابعة اداء موقعك

متابعة اداء موقعك شيء مهم لاي طور او صاحب موقع و متابعة الاداء تنقسم لعدة اقسام

  • متابعة الزيارات و مصدرها
  • متابعة حملاتك الاعلانية
  • متابعة اداء الخادم server الموقع
  • متابعة الاخطاء البرمجية و ملفات الـ log

وغيرها من الامور لكن اليوم اردت مشاركة جزء من كود برمجي حول النقطة الاخيرة لمتابعة ملفات الاخطاء و logs في موقعك جزء مما تحدثت عنة في محاضرة web applications scalability problems في مؤتمر CAT Scope12

الفكرة هي تقسيم ملفات التتبع و الاخطاء كل يوم ليسهل متابعة الاخطاء و المشاكل الكود مكتوب ليتم تنفيزة من خلال cron job

if (file_exists('../tmp/logs/debug.log')) {
rename('../tmp/logs/debug.log', '../tmp/logs/debug - '.date('Y-m-d',time()).'.log');
echo 'debug.log renamed' . '<br/>';
if (file_exists('../tmp/logs/error.log')) {
rename('../tmp/logs/error.log', '../tmp/logs/error - '.date('Y-m-d',time()).'.log');
echo 'error.log renamed' . '<br/>';

ما سيقوم بة هذا الجزء هوا اعادة تسمية ملفات التتبع و الاخطاء كل يوم باضافة تاريخ اليوم لاسم الملف لذا عندما يقوم الموقع بانشاء ملف جديد بالاخطاء في اليوم التالي يتم اعادة تسمية, هكذا تستطيع متابعة الاخطاء وما يحدث في موقعك بشكل دوري (الكود مكتوب داخل CakePHP و يجب تعديل مسار الملف ليتناسب مع موقعك)

web applications scalability problems – presentation

CAT Scope 12 المؤتمر الثاني عشر من نوعة تنظمة اسرة الـ CAT في جامعة المنصورة ومنذ الامؤتمر رقم 5 وانا كنت مواظب علي حضور هذا المؤتمر لما فية من استفادة وقررت ان اشارك و احاول رد جزء لنفس المجتمع شاركت من قبل بتقديم ندوات في الـ CAT Scope (“Web development not just Code”) , فعاليات اخري مثل Twenty CAT

شارت هذة المرة بعرض يشرح المشاكل التي قد تواجة مطوري المواقع و يحتاجوا معها لعملة توسع بسبب زيادة عدد المستخمين, كانت الندوي لا تتحدث عن الادوات التقنية لحل المشلة بل كنت احاول توضيح كيفية التفكير في المشكلة و طريقة اكتشاف الحل الانسب, Continue reading web applications scalability problems – presentation