0

I am curious, I am creating a flickr plugin for wordpress. I have noticed that the PHP that I have written is fairly slower then the same javascript I have written.

I know that Javascript is run client side so it will be faster as long as there aren't numerous processes already hogging the processor. With PHP running remotely I know that it is all based on connection and what is going on with the server. I was wondering if one was better to use than the other and if DOM is maybe not the best way to go grab XML. In this case in PHP I am using DOM to go and get the XML and then parse it out. With Javascript I am using SOAP to parse the same XML.

4
  • If you can afford it making the client work instead of your server is good sometimes. Commented Apr 17, 2012 at 14:57
  • Some people disable JavaScript by default. Commented Apr 17, 2012 at 14:57
  • 2
    Are you sure it's the XML processing that's slower? Add some tracing and timing calls into your code and log them - the root cause could be something else entirely. It's always good to confirm your hypothesis. Commented Apr 17, 2012 at 15:13
  • Rory, indeed I did tracing for all of this the problem occurs when I am trying to call the XML DOM for each image in an imageset. I have gone through my big O and I am right now a O(n) so I know it isn't anything due to my logic or programming. It just takes awhile for the server to run the php get the DOM and then do it's job. Thanks Commented Apr 17, 2012 at 18:01

2 Answers 2

4

Assumption

  • JavaScript is required for this plugin.
  • JavaScript testing was only done on your development machine.

I think you need to rethink your metrics. In your particular case JavaScript is faster than PHP, but I don't see that being the case across the board. I'm assuming you're on shared hosting as are probably most end users of your plugin, so your PHP will not be on the fastest servers. Like Rory said above. It is best to diagnosis why your PHP is slow. With JavaScript you have to take into account the average user's device speed which could range anywhere from awful to amazing. My guess is your PC is somewhere near the higher end of the spectrum.

Without any code provided it's tough to give a definitive answer. I would recommend trying your JavaScript version of the plugin on as variable a range of devices and browsers as possible. Hitting on things like iPads and cellphones.

Due to that JavaScript potential performance pitfalls on low-end devices, I would probably perform the task on the server unless investigation shows that, in your case, the JavaScript is performant across the board.

Sign up to request clarification or add additional context in comments.

2 Comments

Ya I agree these are all good points. One of the things I have a problem with is just that javascript can be such a pain when trying to implement some OO ideology to it. I was hoping I could get around some of the global variable pitfalls to javascript by using PHP however now I am seeing like you said that the cost of PHP run through potentially horrible connections or a server that is under a huge load could just destroy the purpose of having the app to begin. Looks like it is back to the drawing board. Thanks!
Ok so I solved my initial problem. Using kind of what you said. I am using PHP to grab the main data which it achieves in 0.005 ms which I have tested on a few different platforms. Then I am using Javascript to get all of the huge data I need which is achieving in about the same time. Thanks everyone!
0

You also can run javascript in the server-side with the V8JS class in PHP since version 5.3.3+ http://ar.php.net/manual/en/book.v8js.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.