6 Replies - 7688 Views - Last Post: 04 March 2010 - 07:40 PM

#1 godmoktail  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 76
  • Joined: 10-May 08

Run PHP scripts on client browser, or execute on server?

Posted 04 March 2010 - 06:02 PM

I'm creating a simple server that receives HTTP requests for files, and replies to those requests with the files. However, some files might be scripts (login.php for example). Does it make sense to just send the client the PHP script and let it execute (query the database, produce results) on their side, or execute the script on the server side, and send the built result to the client?

I will be using a PostgreSQL database, therefore, I prefer having the PHP scripts query the database rather than my server (C++) to reduce complexity of the project.

What do you think of my approach, and should I just send the PHP scripts to the client and let their browser handle it?

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Run PHP scripts on client browser, or execute on server?

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Run PHP scripts on client browser, or execute on server?

Posted 04 March 2010 - 06:04 PM

PHP is a server-side language, it cannot be executed client-side (so it has to be executed on the server)
Was This Post Helpful? 0
  • +
  • -

#3 godmoktail  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 76
  • Joined: 10-May 08

Re: Run PHP scripts on client browser, or execute on server?

Posted 04 March 2010 - 06:25 PM

When a client requests a file, let's say homepage.html (with a form to login), after the user submits, the action says run a php script. So I would have to execute a PHP script from C++, store the result within C++, and send the result (through a socket) to the client?
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,066
  • Joined: 10-May 07

Re: Run PHP scripts on client browser, or execute on server?

Posted 04 March 2010 - 07:06 PM

View Postgodmoktail, on 04 March 2010 - 07:02 PM, said:

Does it make sense to just send the client the PHP script and let it execute (query the database, produce results) on their side

Well not really.

1.) Does the client have the database for PHP to access?
2.) Does the client have a PHP processor?
3.) Do you really want the client to have control over variable & value evaluation?

The answer to those three questions will be a strict "no". In short, PHP prepares viewable code on the server that is given to the clients browser for viewing. PHP, ASP, & Database operations are processed on the server, HTML & Javascript are processed by the clients browser.

View Postgodmoktail, on 04 March 2010 - 07:25 PM, said:

So I would have to execute a PHP script from C++, store the result within C++, and send the result (through a socket) to the client?

I don't understand how C++ got mixed in with this. If you are using C++ that's cgi/bin, which is also client side. You use PHP or C++, most likely not both.
Was This Post Helpful? 0
  • +
  • -

#5 godmoktail  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 76
  • Joined: 10-May 08

Re: Run PHP scripts on client browser, or execute on server?

Posted 04 March 2010 - 07:35 PM

Well, my server will be written in C++ (there's nothing to change this requirement). That is, the C++ server will be the one listening on a socket for HTTP requests. I want to use PHP to deal with the Postgres database, so I would like to have the server (C++) execute these scripts, which makes dealing with the database, and generating dynamic html pages easier.

I hope you understand my train of thought. Am I missing/ignoring some details?

"If you are using C++ that's cgi/bin, which is also client side."
What do you mean by "that's cgi/bin"?

PS. I'm new to web development(experienced desktop application development), so the architecture or procedures to go about usual web stuff I'm not to0 familiar with.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,066
  • Joined: 10-May 07

Re: Run PHP scripts on client browser, or execute on server?

Posted 04 March 2010 - 07:38 PM

Quote

What do you mean by "that's cgi/bin"?

You didn't mention before that the C++ is handling the html request. Apache loads a PHP module to handle the PHP language/requests. I don't know Apache deep enough to help with this project.
Was This Post Helpful? 1
  • +
  • -

#7 godmoktail  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 76
  • Joined: 10-May 08

Re: Run PHP scripts on client browser, or execute on server?

Posted 04 March 2010 - 07:40 PM

Note: I understand that both PHP and C++ can be used to create an application to read from sockets, effectively allowing both to fulfill HTTP requests.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1