Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-04-17 23:25:16
Point:250 Replies:10 POST_ID:828478USER_ID:11059
Topic:
Hypertext Markup Language (HTML);PHP Scripting Language;JavaScript
At the beginning, I make a table of 300*40 cells by javascript and the display speed is good so I try
to convert the javascript code into php code since I want to protect my code for a try tutorial.
The speed of table by php is obiviously slower than javascript. So I get a few easy question.
1) Using javascript has adavantage that is because he is client-side language, the speed of display table
is depened on users' broswer and CPU of PC (besides html page to user pC), so to server's workload is not too much
Is it correct and right ?
2) If I using php to make a table, that will be issue because it is server-side languge. If there is 1000 users
to submit php request from my domain at the same time for example, , the server needs to generate 1000 table for 1000 users so it will slow down speed. Is it right ?
3) I am using domain is share domain so it might be slow than my PC, so using php might not have any advantage
under such condition, Is it correct?
4) Last one, people are using php because it is just for security issue to protect the code not being seen by users and for the job
of checking password and login process Is it correct ? If so ,if server and my PC is same CPU speednand for one user only to
use the server, php speed shoud be similar to javascript because both languague is based on C languag , Is it right ?
5) If not critical code to protect or security, always stay on javascript (not php) that will have speed advantage always, Is it right ?
Please advise
Duncan
to convert the javascript code into php code since I want to protect my code for a try tutorial.
The speed of table by php is obiviously slower than javascript. So I get a few easy question.
1) Using javascript has adavantage that is because he is client-side language, the speed of display table
is depened on users' broswer and CPU of PC (besides html page to user pC), so to server's workload is not too much
Is it correct and right ?
2) If I using php to make a table, that will be issue because it is server-side languge. If there is 1000 users
to submit php request from my domain at the same time for example, , the server needs to generate 1000 table for 1000 users so it will slow down speed. Is it right ?
3) I am using domain is share domain so it might be slow than my PC, so using php might not have any advantage
under such condition, Is it correct?
4) Last one, people are using php because it is just for security issue to protect the code not being seen by users and for the job
of checking password and login process Is it correct ? If so ,if server and my PC is same CPU speednand for one user only to
use the server, php speed shoud be similar to javascript because both languague is based on C languag , Is it right ?
5) If not critical code to protect or security, always stay on javascript (not php) that will have speed advantage always, Is it right ?
Please advise
Duncan
Author: duncanb7 replied at 2024-04-20 07:44:46
Thanks for your reply
It help to start to know more
It help to start to know more
Expert: Ray Paseur replied at 2024-04-18 02:54:52
Hi, Brian. Just up early. Dog has been jumpy. We live near a forest and when springtime arrives, there is a lot of animal activity in our yard. He is on heightened prey-drive for squirrels and rabbits. Unfortunately he is not a very bright dog and often barks at his prey before he tries to chase it. This wakes everyone up (most notably the prey).
Expert: bportlock replied at 2024-04-18 02:16:40
@ray - you're up early or have you moved to Europe?
;-)
;-)
Assisted Solution
Expert: Ray Paseur replied at 2024-04-18 02:14:17
62 points EXCELLENT
@Duncanb7: You might want to start by comparing the things you can do with JavaScript and the things you can do with PHP. Think of a web site or service as having two layers - a client layer (the software running on the client machine) that runs JavaScript, and a server layer (remote and separate) that runs PHP. Here are some of the things you can do at the client layer. Change the color of the screen, manipulate data sent from a server, issue alerts. On the server side of things, you can store and retrieve information from a data base that contains shared information from lots of clients, you can generate HTML and send it in response to client requests, etc.
To the "which is faster" question - this is like asking which is hotter, a frying pan or an oven. You might be able to measure each of them and get an answer, but the answer is meaningless. The more important question is, "what do you want to cook?" If it is a whole turkey, a frying pan is the wrong tool. And if it is an egg, the pan would make sense, but the oven would not.
The strategy of offloading work from the server to reduce the server load seems to me to be one that makes sense only at the highest levels of loading. Facebook and Google do this sort of thing. The real reason for putting certain functions on the client machine is to make for a richer, more interactive, user experience.
PHP code runs on the server, so it is generally invisible to users, but it is usually "hidden" by self-important novices who think their code needs to be kept a secret. Once we see how it works, it is not a secret any more, and most knowledgeable programmers would be able to replicate the functionality, whether you use open source or try your hardest to obscure your work. The value of your underlying data is what is important, not the code you write to access the data.
JavaScript can be turned off, or modified by the client. What this means in terms of security is that you cannot use JavaScript for any security-related activity, such as validating the contents of client forms. It is there for the pleasure of the client and nothing more. If you are going to receive external data and use it to modify your server's data model, you must do the data validation on the server, after all the data is received.
Those are just a few thoughts, but I hope they help you consolidate your ideas about the different uses for JavaScript and server-side programming.
To the "which is faster" question - this is like asking which is hotter, a frying pan or an oven. You might be able to measure each of them and get an answer, but the answer is meaningless. The more important question is, "what do you want to cook?" If it is a whole turkey, a frying pan is the wrong tool. And if it is an egg, the pan would make sense, but the oven would not.
The strategy of offloading work from the server to reduce the server load seems to me to be one that makes sense only at the highest levels of loading. Facebook and Google do this sort of thing. The real reason for putting certain functions on the client machine is to make for a richer, more interactive, user experience.
PHP code runs on the server, so it is generally invisible to users, but it is usually "hidden" by self-important novices who think their code needs to be kept a secret. Once we see how it works, it is not a secret any more, and most knowledgeable programmers would be able to replicate the functionality, whether you use open source or try your hardest to obscure your work. The value of your underlying data is what is important, not the code you write to access the data.
JavaScript can be turned off, or modified by the client. What this means in terms of security is that you cannot use JavaScript for any security-related activity, such as validating the contents of client forms. It is there for the pleasure of the client and nothing more. If you are going to receive external data and use it to modify your server's data model, you must do the data validation on the server, after all the data is received.
Those are just a few thoughts, but I hope they help you consolidate your ideas about the different uses for JavaScript and server-side programming.
Assisted Solution
Expert: bportlock replied at 2024-04-18 02:13:59
62 points EXCELLENT
What DaveBaldwin is saying boils down to these simple statements
- Javascript runs only on the client PC not of the server
- PHP runs only on the server, not the client PC
From those two sentences alone it is obvious that comparing speed between javascript and PHP is pointless because you are comparing two different computers running two different languages. To expand on his later point "f the table cells need to change color for navigation, then you use javascript because PHP on the server can not do that without reloading the page each time. " PHP can only generate an entire HTML page and present it to your browser as a complete HTML page, it cannot change anything except by building a new version of the page and sending that to your browser.
Javascript, because it is a client side language, can take a page and alter bits of it directly. As for AJAX, because it is a combination of Javascript, PHP and the XMLHTTPRequest object, will run at the speed of the slowest of those 3 components so AJAX may have the worst performance of the three methods.
- Javascript runs only on the client PC not of the server
- PHP runs only on the server, not the client PC
From those two sentences alone it is obvious that comparing speed between javascript and PHP is pointless because you are comparing two different computers running two different languages. To expand on his later point "f the table cells need to change color for navigation, then you use javascript because PHP on the server can not do that without reloading the page each time. " PHP can only generate an entire HTML page and present it to your browser as a complete HTML page, it cannot change anything except by building a new version of the page and sending that to your browser.
Javascript, because it is a client side language, can take a page and alter bits of it directly. As for AJAX, because it is a combination of Javascript, PHP and the XMLHTTPRequest object, will run at the speed of the slowest of those 3 components so AJAX may have the worst performance of the three methods.
Author: duncanb7 replied at 2024-04-18 00:28:07
--->If the table cells need to change color for navigation, then you use javascript because PHP on the server can not do that without reloading the page each time.
I understand just what you said, but i still get confused on the statement, please help to make a simple example for us if possible
I understand just what you said, but i still get confused on the statement, please help to make a simple example for us if possible
Expert: Dave Baldwin replied at 2024-04-18 00:08:35
AJAX is a combination of javascript, the xmlHTTPrequest function in the browsers, and a server side language, often PHP. AJAX is an Excellent example of how we use javascript and PHP together and how they complement each other. You can Not do AJAX with only javascript or only PHP. It requires javascript in the browser and a language like PHP on the server. This tutorial tells all about it: http://www.w3schools.com/ajax/default.asp
'getelementsbyTagName' is a javascript function. http://www.w3schools.com/jsref/met_doc_getelementsbytagname.asp
'getelementsbyTagName' is a javascript function. http://www.w3schools.com/jsref/met_doc_getelementsbytagname.asp
Author: duncanb7 replied at 2024-04-17 23:58:25
--->If the table cells need to change color for navigation, then you use javascript because PHP on the server can not do that without reloading the page each time.
I don't unsderstand at this point above, we can change color by DOM getelementsbyTagName to change the table arrtibutes or
add anything, And Ajax cab be also used in PHP, why you said, could you explain more and make an example if possilbe
Thanks your advise
Duncan
I don't unsderstand at this point above, we can change color by DOM getelementsbyTagName to change the table arrtibutes or
add anything, And Ajax cab be also used in PHP, why you said, could you explain more and make an example if possilbe
Thanks your advise
Duncan
Assisted Solution
Expert: Dave Baldwin replied at 2024-04-17 23:48:20
63 points EXCELLENT
PHP and javascript complement each other but they are not interchangeable. A table of 300*40 cells has almost no practical value so it doesn't represent a 'useful' test even if it does show a difference in speed.
If a table needs to be filled from a database, then PHP is the thing to use because javascript in the client can't access a database on the server. If the table cells need to change color for navigation, then you use javascript because PHP on the server can not do that without reloading the page each time.
In practical web design and programming, you use the language that is appropriate for the function. PHP and javascript each have their place and can not replace each other.
If a table needs to be filled from a database, then PHP is the thing to use because javascript in the client can't access a database on the server. If the table cells need to change color for navigation, then you use javascript because PHP on the server can not do that without reloading the page each time.
In practical web design and programming, you use the language that is appropriate for the function. PHP and javascript each have their place and can not replace each other.
Accepted Solution
Expert: sshah254 replied at 2024-04-17 23:32:08
63 points EXCELLENT
1. Yes, the server's load is not too much in this case. However, the speed of JS will depend on how it is implemented.
2. Not really. It all depends on what you are generating, how it is being generated, the capability of the server, the load on the server, etc. I believe you are using a hypothetical example of 1000 users ... most likely you will not have a 1000 users hitting your server at the same time.
3. Again, not really. Although it is a shared machine, it may have much more capacity than a regular machine. Also, the server is just usually dedicated to PHP/Apache/MySQL. The end user machine has a lot more things to do - not only JS.
4. Partially true. PHP is used to get a lot more functionality than is possible with JS. The added benefit is that it hides a lot of code too (sort of security). As far as speed comparisons of PHP to JS is concerned, I do not have raw information on that, as it is a difficult problem to test.
Ss
2. Not really. It all depends on what you are generating, how it is being generated, the capability of the server, the load on the server, etc. I believe you are using a hypothetical example of 1000 users ... most likely you will not have a 1000 users hitting your server at the same time.
3. Again, not really. Although it is a shared machine, it may have much more capacity than a regular machine. Also, the server is just usually dedicated to PHP/Apache/MySQL. The end user machine has a lot more things to do - not only JS.
4. Partially true. PHP is used to get a lot more functionality than is possible with JS. The added benefit is that it hides a lot of code too (sort of security). As far as speed comparisons of PHP to JS is concerned, I do not have raw information on that, as it is a difficult problem to test.
Ss