Jump to content
xisto Community
khalilov

Some Php Questions

Recommended Posts

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

Edited by khalilov (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.