HOME       >>       Programming

Some Php Questions


khalilov

I was in my village for the last two days so i did alot of PHP scripts and came up with some questions:1-When a PHP script is run, the server is doing something. So am I using bandwidth in the process? If so how much, lets assume the script gets a row from a database and display it. Does the script use bandwidth equal to the size of the data desplayed or the data the script went through whiel searching the database.2-I want a script to run every X minutes, how do i do that?3-In a script, i call some data from the database having a same trait and put them in a table through a while loop. Now after the loop ends i want to use them again, can i put them in an aray or somethign while in the loop?4-I want to make a countdown timer for my entier site, meaning it has to be in the database or something, also when it is viewed i want it to keep counting down , meaning the viewer doesn't need to refresh the page to see how much time is left. Also when the time hits 0 i want it to reset back to a value i set and i want a php script to be automatically run.I forgot the other questions , i'll add them later O-o


yordan

1-When a PHP script is run, the server is doing something. So am I using bandwidth in the process? If so how much, lets assume the script gets a row from a database and display it. Does the script use bandwidth equal to the size of the data displayed or the data the script went through while searching the database.

In fact, there are several types of bandwidth : memory, disk, network. Usually, for a web server, people are sensitive to network bandwidth.
When your script is running, it uses cpu power, disk power and Ethernet power.
The script uses cpu power and memory power simply in order to run. Your computer account probably has some limitations concerning the cpu power and the memory usage allowed to each user.
The script uses network power when receiving data from you, and sending data to you. The data the script sends to you and receiving from you are the network bandwidth.
While your script is reading data from the disks attached to the computer, it uses the disk bandwidth. You could imagine that a poorly designed php program reads several hundreds of gigabytes on the computer disks in order to retrieve a single byte data (for instance the question "is somebody else as poor as myself" can make read the whole salary data, and return a single value : "NO"). This uses several hundreds gigabytes from the disk bandwidth, and only one byte from the network bandwidth.

khalilov

In fact, there are several types of bandwidth : memory, disk, network. Usually, for a web server, people are sensitive to network bandwidth.
When your script is running, it uses cpu power, disk power and Ethernet power.
The script uses cpu power and memory power simply in order to run. Your computer account probably has some limitations concerning the cpu power and the memory usage allowed to each user.
The script uses network power when receiving data from you, and sending data to you. The data the script sends to you and receiving from you are the network bandwidth.
While your script is reading data from the disks attached to the computer, it uses the disk bandwidth. You could imagine that a poorly designed php program reads several hundreds of gigabytes on the computer disks in order to retrieve a single byte data (for instance the question "is somebody else as poor as myself" can make read the whole salary data, and return a single value : "NO"). This uses several hundreds gigabytes from the disk bandwidth, and only one byte from the network bandwidth.


So are you saying the only effect is my site running slower O.o

wutske

of course it will run slower. It's as in real life:Someone (a user) asks you (the server) to get a purple shirt (data) out of your closet (database). The words he sais when asking you and the purple shirt is what is being sent over the internet, nothing big actualy. Between the asking and returning the shirt, you go to your closet, open it, search between all your shirts, eventualy find the purple shirt and take the purple shirt, that is actualy what a database does, these are very basic tasks and usualy don't require a lot of time, you'll hardly notice that the site is slower (except if the database is realy huge, a lot of users are using the database and the script is poorly designed). Don't be afraid to loose a few miliseconds, you won't notice it.For your second question you might consider using cron jobs if your server is running linux.


khalilov

of course it will run slower. It's as in real life:Someone (a user) asks you (the server) to get a purple shirt (data) out of your closet (database). The words he sais when asking you and the purple shirt is what is being sent over the internet, nothing big actualy. Between the asking and returning the shirt, you go to your closet, open it, search between all your shirts, eventualy find the purple shirt and take the purple shirt, that is actualy what a database does, these are very basic tasks and usualy don't require a lot of time, you'll hardly notice that the site is slower (except if the database is realy huge, a lot of users are using the database and the script is poorly designed). Don't be afraid to loose a few miliseconds, you won't notice it.

For your second question you might consider using cron jobs if your server is running linux.


I still haven't got a server, iam goan get hosted at Xisto soon, is this possible in Xisto?

toby

Yes.1. The only sort you have to care about is how much data is sent out from you, and generally html files are negliable.2. Crontab, doable here.3. Yes, learn loops and arrays of php.4. I would suggest contrab for the server, and javascript for the users.


yordan

2. Crontab, doable here.4. I would suggest contrab for the server, and javascript for the users.

Not so sure. Xisto sites are hosted on Linux systems. However, I'm pretty sure that currently, ssh is not allowed on the free hosting plans. And also, probably, cron.allow is only for admins.
Regards
Yordan

TavoxPeru

2-I want a script to run every X minutes, how do i do that?

You can do that with a crontab job, view the following topics for some information:

Want To Update Every Hour

How To Use Cron Jobs To Save Two Images?

3-In a script, i call some data from the database having a same trait and put them in a table through a while loop. Now after the loop ends i want to use them again, can i put them in an aray or somethign while in the loop?

Yes, you can.

 

4-I want to make a countdown timer for my entier site, meaning it has to be in the database or something, also when it is viewed i want it to keep counting down , meaning the viewer doesn't need to refresh the page to see how much time is left. Also when the time hits 0 i want it to reset back to a value i set and i want a php script to be automatically run.

You can do that with PHP and plain Javascript, aditionally you can also use Ajax. View the following topic How To Create An Online Timed Test With PHP? for some ideas about it, and if you decide to use it please let me know if you want the code.

 

Best regards,


toby

Oh ok, I've seen cpanel with a crontab jobs section.



VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.