Jump to content

[SOLVED] General question....PHP vs. JavaScript?


galvin

Recommended Posts

In deciding whether to use PHP or Javascript for a certain part of a website, I'm being told that if Javascript can do it, I should use Javascript because it doesn't tax the server my website is on.

 

Would you agree with that statment, or is there more to it than that? 

 

I've been working with PHP for about a year now and I literally just started teaching myself Javascript a few days ago, and I'm having trouble deciding when to use PHP and when to Javascript.

 

If anyone has any thoughts/advice on the matter, I'd be all ears. ::)

Link to comment
Share on other sites

Two separate items. Javascript is client side. PHP is serverside.

 

The problem with javascript is it can be disabled on the client. PHP code will always be executed. So you have to ask yourself, is the task you want to preform necessary? Cause if it is, then PHP is the sure fire way to do it.

Link to comment
Share on other sites

thing is, if someone goes to your site with Javascript off in their web browser, your site becomes dead.

 

people can't turn off PHP.

 

even if you are using Javascript for form validations and such, always do the same validations with PHP as well.

 

PHP, if written properly and efficiently, won't tax the server to any noticeable degree, so don't worry about that.

Link to comment
Share on other sites

Ya and... no - I mean lets take that thery

 

if Javascript can do it, I should use Javascript because it doesn't tax the server my website is on

 

Lets say you're processing a form. Use Javascript to ensure all the fields are complete, and if that passes, then post the form. The problem with this is, what if the person had Javascript turned off?

 

So to prevent that use both. Javascript to check the form fields, then use php isset() to check on form fields as well. I guess in the end of this example, is it REALLY needed to use javascript.

 

I think its a mixture of both, and its for you as the programmer to decide what to use and where.

Link to comment
Share on other sites

I'm not saying I do (yet) ;), but lets say I had a website that had CRAZY traffic.  I'm talking thousands of unique visitors per day.

If I did a lot of things on my site with PHP that Javascript could have done, will that tax my server significantly more than if I had used Javascript instead?

 

I guess my problem is that I don't know enough about bandwidth from traffic vs. performing PHP tasks in terms of their effect on the server.  I just feel like IF there are thousands of visitors a day and for each visit the server is being accessed via PHP, logic seems to indicate that the server speed will suffer because of it.  But in actuality, maybe it's just the heavy traffic ALONE that would slow the server down, and not so much PHP performing tasks for all of that traffic. 

 

Mrmarcus said

PHP, if written properly and efficiently, won't tax the server to any noticeable degree, so don't worry about that.

 

But does that rule still apply if I have a HUGE amount of traffic?  ;) 

 

I think I just talked myself into my main question.  What taxes a server more, overall traffic or PHP tasks being performed? (I realize that might be a question that depends on many variables but figured I'd ask anyway :) )

 

Also, does anyone know any percentages as far as the percent of internet users with Javascript turned off?  It's gotta be really low I would think.

Link to comment
Share on other sites

But does that rule still apply if I have a HUGE amount of traffic?   ;) 

 

PHP and MySQL are made for massive amounts of Traffic. I believe that Facebook and yahoo are coded in PHP (not sure on the DB).

 

Do not worry about the traffic. Honestly, javascript would only do a minor amount it is not worth it. PHP is extremely efficient if coded properly. Traffic tasks the server more. PHP will not as long as it is coded properly. Simple as that.

 

To think, this page took 0.071 seconds to create and ran 21 MySQL queries. If it did not have to run those queries it would have loaded up a ton faster. You are bogging yourself down with something that is not even relevant.

 

The traffic will be the same with or without Javascript, so will PHP executing tasks. Simple as that. Handle data where it needs to be handled.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.