From time to time, each of us can recall situations where you are doing everything right, and the system is “crazy.” You fight, you try to find a problem, you have already gathered the consilium around you - no one can understand what's the matter, and then what time passes and the illumination comes. And you understand that I was stupid, that here it is, a mistake. On the surface lay. Then you can tell such stories in a professional get-together.
A little offtopic with a programmatic theme for life. About seven years ago, an amusing situation occurred with me in Turkey, in a hotel. It took me for some reason to stroke a T-shirt there and I tried to formulate a deep thought in English, well, how could. At the reception, he was also not very well known, they tried to understand me.
“Tu a'yron, ah niid that iron,” I say to the girl. To iron. To - iron. White t-shirt. To iron. She waves her head: “Ok, ok, mister!”. She asked if I would be in my room. Yes, I answer, where am I still to be with the iron.
')
I sit in the room. Then there is a knock at the door, I open it and almost crash into the floor. A Turkish man looks at me and does not understand anything. In his hands he holds a tray on which two ayran.
Such situations sometimes occur with computers, in programming, and in administration. It all started with someone else's story about mail, which
did not go further than 500 miles . I published it on LiveJournal in 2003, so there is still a noticeable visit to it. Apparently, touches the topic of people, yes.
On my home laptop (macbook) my mouse suddenly wedged. You move the mouse cursor, and he takes away windows with him. I reboot the computer (it was not easy to do it without a mouse), it works for about five seconds, and then again the same garbage. That's all for no reason. Worked a minute ago! I did not put anything and did not write to the disk, did not change it. Just from scratch rraz! - and does not work. And after all, even nothing can be done, the mouse does not work, from the keyboard I am confused little about makosi. In five seconds at the beginning, of course, you do not have time. I broke the whole head, what could it be.
And then I went to the kitchen. The touchpad is working. By itself. Whew, I thought, miracles happen, but that's all, the problem is in the past, and returned to parsing the mail.
In the evening I went back to the room with the laptop. Well, stick trees, again. In some places, the mat appeared.
The thought came to return to the kitchen. I drove her away because this is nonsense. But she did not retreat. Returned. Cheers cursor moved !!! Returned to the room - again blocked.
I already thought about the dosimeter, really.
He sat down and began to think. And I understood.
You will laugh. The children with toys pressed the button of the bluetooth mouse in the corner of the room, which I had already forgotten about - it was somehow more convenient for the touchpad. To the kitchen, the bluetooth no longer finished off.
So, all this is an introduction to the topic of today's note. The theme will be about the site. Do not believe it, I remembered about the mouse, about Ayran, when I tried to understand last night what the fuck was.
I am now making a prototype of the site, such a fast knee-type prototype of the site and the online version of my
Wordrive game. The game is now on revision at Apple, after two weeks it will start. The prototype is designed to test several technologies and this noble mission he has already completed. But sometimes you need to repair it while it is still a prototype.
The site works on the basis of RewriteEngine - this is a technology from Apache that allows, in particular, to convert addresses like / folder1 / folder2 / into something like /script.php?param=/folder1/folder2. I was set up so that it does not convert in only one case - if the resource pointed to by the path really exists. This allows you to refer to images, for example, /img/picture.png and this path will not be “fed” to the script script.php. Because there is a special line.
Let me give you the full content of .htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /script.php?param=$1 [L,QSA]
In script.php, I have a condition like the following,
clearlog();
$param = $_REQUEST['param'];
if ($param == "/folder1/folder2/")
{
// BLOCK A : process folder1 - folder2
writelog ('1');
} else
{
// BLOCK B :
writelog ('2');
}
And here I see that with ONE access to the browser, TWO lines are written to the log. Dvoechka and one.
I rubbed my eyes. I tried again. Erased the log file. I wrote a call to the browser in incognito mode, opened the developer's toolbox, checked that there was one request. SAME. There are two lines in the log. 2 and 1. It is a pity, there is no access to access-logs, I would have looked there. But it is not.
Well, I thought, this is a hosting issue. There, probably, incorrectly process requests. They have a higher level. Htaccess server level and there are also rules. Probably processed twice. And wrote them an application.
Together with the hosting we made sure that:
- if you erase .htaccess or remove RewriteEngine from there, everything works,
- if you use Firefox, everything works,
- One chrome at the hoster also did not give out problems.
The guys from the hosting were busy three hours. As a result, they sent a letter:
, .
, ,
"Chrome" ~/public_html/.htaccess.
, .htaccess.
. ,
"Chrome". ,
"FireFox", .
I received this letter at home at six in the morning. While driving to work, I realized what the problem was. But it was still worth checking out.
As I expected, it turned out to be in favicon.ico. The browser sends a request for this file in parallel with the request for the script. Google Chrome does this with every request. Firefox, probably once having received a piece of my HTML from a script instead of an icon, realized that something was wrong and did not apply anymore. And Chrome is persistent - it jerks this file. This was the case in the logs. And the favicon.ico file, of course, was not on the site. And here the rule worked - you need to redirect it to the script, /script.php?param=favicon.ico Inside, the logic followed a different path, and writing to the log worked, and all the debug echo were output only for the second request.
By the way, for the prototype of the
my.wordrive.com service I was pleased with the task of writing the translation function from decimal to
62-bit system and back. After all, there are such tasks! .. And without it in any way.
That's what I love programming for.