Home Links
Home Page
How to us to correct the person who has entered
Yandex - like search by the hands
Stemmer.
Creation of sites - model of qualitative imposition
Entrance parameter of function is the file from six elements
Promotion of a site in Rambler
The good design should make a profit
Validnost` HTML
Perenapravlenie mistakes in a browser - 100 % as in PHP
Terrible animal the traffic
Cajt with help HTML:: Mason
Choice of the module
Bases of
Creation of a site
Adjustment of a site
TT - the counter of the traffic
GetCurrBytes
OnOverflow
Small improvements of our counter
 

Terrible animal the traffic

Domestic users seldom think of that, that such the Internet traffic - quantity{amount} kilobyte, a megabyte, a gigabyte and further with all stops, - downloaded to them on a computer from the Internet. Such concept is almost unfamiliar to them - simply by virtue of that at access in the Internet on dialapu the traffic to consider it is not necessary, in fact at such connection pay only time which has been lead{which has been carried out} in the Internet, but in any way not downloaded megabytes. But it and is understandable - that such especial it is possible to pump up on dialapu at his{its} speeds? In general, anything. The telephone line is not intended for uploading films, video clips and so on. Even a music through dialap to extort inconveniently - too completely not telephone volumes...


Other business - vydelenka or a regional network. When the domestic user has selected channel or "cord" of a regional network - he there and then passes in a little bit other megabajto-consumer category. Because now his{its} volumes of consumption from the Network grow approximately on the order. How you think, what volume is downloaded by the average Internet user if to it{him} on a computer the Internet acts through shustruju a local area network, and he spends in the Internet all the day long? About fifty megabytes. And it if he does not swing films, is not fond of music in format MP3 (more precisely, the big fan of everyone schedules and video quite certain{determined} exposing (is not fond of its{her} uploading on a computer from the Network) and not by way of clothes of actors) sorts. Fifty a megabyte - as one kopeechka, and all this the most usual sites and the most usual appetites. And in a month it turns out, by the way, one and a half gigabyte.


In this case the user already should think of that, that such - how much this traffic he consumes the Internet traffic, and the main thing. Because the small amount usually enters into a user's payment of the Internet channel as though prepaid, to be exact free-of-charge megabytes: twenty, thirty, fifty - well, maybe, hundred megabytes, - all this depends on tariff plans. But very much often it happens so, that the user not simply exceeds free-of-charge volume, and leaves far for his{its} frameworks. And then he starts to treat with to the traffic yours faithfully, especially having counted up, in how much tens dollars to him this traffic manages.


Think, when you place the page (or a site) in the Internet, about the traffic it is possible to not reflect? Alas, just also it is necessary to reflect on him, but, as well as in a case with domestic users, - not at once. First you simply do{make} the page and spread her{it} on any hosting. On it{her} there comes the pair - three of friends, and the traffic from this page (the text and a picture which are downloaded automatically by any visitors, zashedshie on a site) makes such pity sizes to which it is not necessary even to pay attention. Thus you pay for a hosting of copeck and more on anything do not reflect.


But the page is to be developed, correctly? And then you start above her, first, densely to work, creating new sections, but also, try to fill a site various contents. Understandably, that with one texts to fill a page it turns out far from being at all. And then in a course goes heavy (in all senses) artillery: music of format MP3, a picture, archives of programs and so on. And if to you will want to put any modern though also very bulky forum and if there every day serious party - then the traffic proceeding from this page, God forbid, will start to come, will start to be measured by rather solid sizes then khoster to you will say: " Druzhok, what feature? ".


This phrase will mean, as loading on khostingovuju the machine, and generjahhijsja by your page the traffic already are not stacked in any way in usual concept of "hosting" for which you pay five - ten dollars a month. You should think of that or to rent the server at the provider, or simply to collect the own server and to place it{him} with the provider (it is called kolokejshn). And then the word the TRAFFIC will rise before you with all inevitability. Because in this case arise about the same problems, as in a case with a regional Internet network: the certain traffic enters into a user's payment (he is already measured in gigabytes because the question is all the same the server, instead of about the local user), but, as a rule, the free-of-charge traffic is monthly exceeded (and is significant) and then you start to pay for these gigabytes. And to pay very much and very quite good money (if at you a visited{an attended} site).


And here that to you is necessary to start to penetrate into any subtleties: than the foreign traffic from Russian (some providers divide{share} these concepts) differs, that occurs in case of so-called piringovykh wars (which will just beat on your pocket) and so on.


After that you will have question (in my opinion, quite natural): and why, actually, you in general should pay the traffic, which generit your page? In fact the users coming on this page, pay to the provider. And pay that traffic which acts to them on a computer (from your page, I emphasize). Then why you for this traffic should pay? It turns out, that providers want and rybku to eat, and on the horsy to drive - in the sense that and from users to take money that they swing the information from your page, and from you slupit` money what users swing the information from your page? Two times to take money for same - unless it is fair? - you, and in this sacred indignation of pure{clean} true almost ask hundred percent{interests}.


That is interesting, until recently such paradoxical situation really took place: providers received money for the traffic both from users, and from owners of servers. Certainly, it is possible to object, what the part of users pays only in time, lead{carried out} in the Internet, however from what they there spend time? That we, founders of Internet pages, these pages have laid out in the Internet. Therefore should not pay the web designer for the traffic, should not! I am deeply convinced of it.


However, fortunately, old times pass. That is pleasant and surprising - among providers already there are firms which are solidary in this question with owners of Internet servers. Not a secret, that for many generjahhikh the traffic of sites providers already for a long time did{made} the certain indulgences (significant discounts allowed him{it} or at all did not take from them payment for the traffic), but all this was in the individual order. And now the first signs has appeared - the company .masterhost has officially declared that she in general ceases to raise payment for the traffic at all kinds of a hosting and kolokejshna (at certain{determined}, the truth, conditions, but these conditions are quite feasible by any sites designed first of all on Russian, instead of the western audience)!


What on it owners of Internet servers can say? Only to clap in ladoshki and is transparent to hint, that well to all providers to pick up this, certainly, the correct initiative. Because if any other providers will prefer to remain in the Stone Age and to continue drat` money both from clients, and from web designers... However, we shall not draw any horrors. I am confident that in fast enough time all providers will pass on the similar form of dialogue with web designers. Because the web designer create that content behind which users come in the Internet and, accordingly, pay money to providers. It is not necessary to forget about it.


The fastest way to define{determine} quantity{amount} of users on a site online

Probably, travelling in the Network, you not time have come across on similar type an inscription « Now on a site 99 person », that means, that except for you at present this site is looked through by 98 person. Most likely, you wanted to write such thing, but did not know as. Following clause{article} will show as itself to write a script, considering{counting} quantity{amount} of visitors on a site at present, that is online.


In the Internet many the ready scripts, allowing to count users online, but time you read this clause{article}, means, you as well as I not especially like to be picked an another's code. Well, in such, a case, give write such script. But before we shall talk about his{its} advantages and lacks.


Advantages.


The relational database that agree, in our Runet (I have his{its} rather free-of-charge part in a kind) is not necessary for him, is doubtless advantage.

Besides doubtless advantage is speed. I was not too lazy to write a similar script with use of a DB and by means of function microtime () (at the very bottom - result of its{her} job - « Time of generation: … ») has measured execution time:

Using sessions - 0,7 ms

Using a DB - 14,2 ms

That is advantage in speed - more than in 19 times! You can say: « Too to me the big business. Only 13 ms a difference », yes they will be right - and if attendance big? Loading on the server and then really such advantage becomes obvious grows.

One more advantage - that the information is stored{kept} in sessions is not closed yet a browser or 1440 seconds (costs{stands} by default in php.ini), in a DB to you should to delete the information on users manually.

And the last - simplicity to declare session it is enough to call function session_start () and to adjust correct in the image of a DB it is necessary to write the whole 15 lines of a code.


Lacks.


There is no detailed statistics - in can learn{find out} only quantity{amount} of users at present, for conducting statistics (hits, hosts …) it is necessary to work all the same from a DB.

It is necessary PHP4 - as it it is paradoxical - yet all khostery have put to itself PHP4.


Actually a script:


<? Php

session_start ();

define ("MAX_IDLE_TIME", 3);

function getOnlineUsers () {

if ($directory_handle = opendir (session_save_path ())) {

$count = 0;

while (false! == ($file = readdir ($directory_handle))) {

if ($file! = '.' ** $file! = '..') {

if (time () - fileatime (session_save_path (). '\'. $file) <MAX_IDLE_TIME * 60) {

$count ++;

}

}}

closedir ($directory_handle);

return $count;

} else {

return false;

}}

echo ' Users online: '. getOnlineUsers (). ' <br/> ';

?>


The REMARK: If you do not have special directory for storage of sessions, is simple at once the first line add:



session_save_path ("/path/to/custom/directory");


Now we shall walk by separate parts of a code:



session_start ();


The next line of a code is an announcement of some constant during which users will be considered active, that is present at present on a site. In our example - 180 seconds, that is if pol`zovatel`` has not passed on new page or has not reloaded this during 3 minutes he is considered left from a site and we any more do not take into account it{him}:



define ("MAX_IDLE_TIME", 3);


Now we declare function getonlineuser () and at once we open a "sessional" directory:


function getOnlineUsers () {


if ($directory_handle = opendir (session_save_path ())) {


Further there is a part of a code which actually and is responsible for calculation of users, function returns online kol-in users:


$count = 0;

while (false! == ($file = readdir ($directory_handle))) {

if ($file! = '.' ** $file! = '..') {

if (time () - fileatime (session_save_path (). ". $file) <MAX_IDLE_TIME * 60) {

$count ++;

}

}

closedir ($directory_handle);


return $count;


} else {

return false;

}


}


And perhaps, it will be reasonable a conclusion of quantity{amount} of users in the end:


echo ' Online of users: '. getOnlineUsers (). ' <br/> ';


All! The script is ready!