I know that in PHP, once you make a request, browser will go in a waiting mode until PHP does it's operation on the server and send the results back. In the meantime, there is no live connection between the browser and the Server while PHP is doing it's work.
I was wondering if same goes with JSP, or connections are handled differently?
First of all JSP is not a programming language. It's just a technology.
I guess that your question goes more into how they work right (Java and PHP)? So to put you in a simple prespective and with a simple answer, take into consideration that both PHP and Java are scripting languages. The main difference is that Java is compiled, before going to the server, to bytecode and then that bytecode is interpreted by JVM when the request is made. On PHP the code is interpreted (translated to bytecode) on the run and executed by the server. On both cases an answer to you request is given back to browser.
On the middle in between your request and the answer, there's JSP which is a technology that makes it possible for you to write HTML with some dynamic scripting in the middle. Much like a template to something (you can also compare it to a templating engine on PHP like twig). You write it only on your views and it gets compiled by getting parsed to Java Servlets.
I hope my answer makes you investigate a little bit because it has a
Related
I have a PHP script for my contact form, but my host is not compatible with PHP scripts. Is there a way to get this PHP code in an <script>tag?
No, there is not. PHP runs on the server, not on the client.
And this is for good reasons. A lot of the things you do with PHP, you wouldn't want to let the client do anyway. For instance loading data from the database - if you gave the client your database password it could get any data from your database.
Some of the things done with PHP could be done in JavaScript instead, but in quite different ways. But not all things could.
If your host does not support PHP, you will either have to live without it or change host.
If your server is not compatible with PHP how do you plan one running PHP? To answer your question, no.
However you could look into using node.js
check this out http://www.nodemailer.com/
No you can't, because PHP is a server-side language, so if your server doesn't support PHP you can't do anything: tags are for client-side languages, such as Javascript, so in this case are useless.
What languages does your server support?
No. If the PHP software itself isn't installed on the server, it isn't available to you to run from any scripts as it is server-side code and has nothing to do with the browser (client-side).
However, if PHP was installed on the server, you can run PHP code within <script> tags as follows:
<script language="php">
// Your PHP code
</script>
(But that isn't good practice)
It's not a good practice to use server side scripts on the front end, better use client side scripts, say javascript. Server side scripting should be used to serve and consume data, to clean user submitted data mainly.
Please make you a favor and enter javascript . There are many good modern frameworks like ANGULARJS and REACTJS, just to mention my preferred.
Having said that, I answer your question, no it's not possible, but your hosting should support any server, so better ask what server scripting does it provide, because it must. The majority of web hostings provide PHP as default.
I'm new to PHP and will like to develop a mobile app that interacts with the server (By putting and pulling datas from the server). Initially I was using Java, but finacial issues I decided to use PHP because getting domain that uses java is expensive.
My question is that does PHP controls multitasking ? reason been that since I will have thousands of users connected to my server probably the same. I llok forward for your answers Thanks
How should PHP have control over multitasking?
PHP interprets a PHP-Script to one point in time when a http-Request occurs on the Script.
PHP does not do multi-threading. It's a single-process-execution kind of scripting language.
However, when set up as a server-side language, it's usually paired up with a HTTP server like Apache, IIS or Nginx, who manage several child processes to handle multiple requests. - If you set it up like a normal server-side language, on top of one of those HTTP servers, you will have no problems handling a lot of parallel traffic.
Recently, I've been involved in two projects.
The first one is built on php and the second in Javascript (using http://nodejs.org/).
Well, I thought that since php depends mostly on the hosting provider, if the site works in one browser it should work in all the rest. Since Javasscript depends mostly on the browser I should encounter more issues in different browsers.
What about the Javascript part that handle the things between the client and server side?
Am I right? Or I'm not considering something?
Server Side javascript does not runs in browser. So it wont have cross browser issues.
If you're using server-side Javascript, it doesn't matter what browser the client is using. From the browser's perspective, there could just as well be a team of well-trained monkeys keying HTTP responses into a teletype somewhere -- all that matters to them is that you're returning data. It doesn't matter to the client what you're using.
Browser issues are in essence completely independent of PHP, period. After all, at the end of the day when the script finishes then all you get is HTML output.
I am having to switch my site over from ColdFusion to PHP and I am noticing that some JS, fadeslideshow.js, isn't running to smoothly. First I notice that some images aren't being centered as they should and the code seems to run a little choppy. Any clues for this novice?
Php and Cold Fusion are both server-side code. JavaScript is client side. So unless your JavaScript is waiting for an ajax request to load, Php/ColdFusion have absolutely no impact on your JavaScript's execution speed. Perhaps you're testing with a different browser than the one you were previously using? That would explain the changes.
You might want to fix the following
We have all seen many question on StackOverflow that are founded upon the idea that PHP works like Javascript. Where the person clearly does not understand that PHP is a Preproccessor and only works before the page is sent out.
A clear example of this is in the following code, where runCommand() will not run when the user presses the button.
Click Me!
as it would in Javascript
Click Me!
I've seen many questions like this that are from new people that just simply don't realize 'how' PHP works.
My question is: Where is a great resource that explains how PHP works?.
I want to be able to redirect people to a page that can get them going on the correct track and know what being a Preproccessor means.
(This also allows me to be lazy and not have to write an explanation every time it comes up, but don't tell anyone!)
If you don't know of a place that describes this well, feel free to provide your own interpretation.
As Carl Smotricz points out, there is a part of PHP that can be used outside of the browser. But I'm mainly talking about in a Apache enviorment where a user requests a web page, and expects to get something back, usually in HTML.
Wikipedia is always a great resource of information. I suggest:
Server-side scripting
vs
Client-side scripting
And Wikipedia also has pictures:
It could be that you're the one who does not understand how PHP works. PHP is a full language interpreter, and it's completely possible to run PHP scripts without a browser, outside of a Web server: On the command line or in an IDE or other GUI environment.
The PHP preprocessor of which you speak is only the function of an Apache module that calls on the PHP interpreter for this particular limited purpose.
The PHP code is interpreted on the server side an only the output of your PHP code will be send to the client.
So if a PHP file is requested, the web server sends the PHP code to the PHP interpreter, waits for the output and then sends the output back to the client.
In short, PHP belongs to the server, it usually then outputs HTML but it's not here for that (or at least, not only for that).
The user browser "sees" only what remains after php did its thing.
Javascript belongs to the client (aka browser): it usually handles the DOM created by parsing the HTML, which is (possibly) produced by executing PHP. Javascript can behave differently in different browsers (everyone who has written JS scripts know about cross-browser problems, do you remember IE6?)
Javascript can't handle database all by itself; It has to rely on a sever-side language (php, maybe? ;) (except if talking about node.js)
BTW, AJAX can be a good reference to understand what exactly PHP does and what JS does.
An important distinction is that JavaScript in a browser is event driven. That is why a click handler is not executed right away as the page loads, for example. The javascript could not be waiting to respond to that click either, if it was not for the event-driven style of dom programming.
I don't really think this is what is meant by the term 'preprocessor'. the client/server side distinction is more important. For instance, have you heard of any other server side language being referred to as a preprocessor when performing the same tasks as PHP?
php responds to http requests in the typical server-side scenario. the browser reads this response and is responsible for rendering it and running any additional dynamic scripts embedded in the response on the client side. that is essentially the division of labor in that scenario.
PHP is server-side scripting language which means all php code is executed before page is sent to the client side. For that reason you will never see
<?php ... ?>
in page source.
On high abstraction level...
You can consider web server (hardware) as component of four different parts. Webserver(software, for example Apache), File system, database and PHP plugin.
So for example when you sent page request (for some page .../example.php) to the web server Apache will try to find that page in file system and if the page exists he will call php plugin to executes all
<?php ... ?>
code (of course including db queries). After that page is sent back to the client side where you can manipulate with page through JavaScript, designed it through CSS...
More on: https://www.youtube.com/watch?v=PemsuAfc7Jw
The reason why PHP scripts are not working in a web browser is only because web browsers do not support PHP (at least I don't know any). This fact is not as trivial as one may think.
And it may sound disturbing, so take a look at HTML specifications on W3C website of HTML 5 and HTML 4.01 (because it has more verbose examples). What you can find? That scripts can be written in languages other than JavaScript!
Here is an example from HTML 4.01 documentation (section titled Specifying the scripting language).
(...)
Here's a more interesting window handler:
<SCRIPT type="text/javascript">
function my_onload() {
. . .
}
var win = window.open("some/other/URI")
if (win) win.onload = my_onload
</SCRIPT>
In Tcl this looks like:
<SCRIPT type="text/tcl">
proc my_onload {} {
. . .
}
set win [window open "some/other/URI"]
if {$win != ""} {
$win onload my_onload
}
</SCRIPT>
Script written in Tcl is perfectly O.K. in HTML! What about PHP? HTML5 documentation says:
A user agent is said to support the scripting language if each
component of the script block's type is an ASCII case-insensitive
match for the corresponding component in the MIME type string of a
scripting language that the user agent implements.
(...) User agents may support other MIME types for other languages,
but must not support other MIME types for the languages in the list
above. User agents are not required to support the languages listed
above.
Thus it is only up to web browser (user agent) if it is going to support PHP or not. Playing with W3C example, PHP aware web browser might have accepted something like this.
<script type="text/php">
function my_onload() {
. . .
}
$win = $window->open('some/other/URI');
if ($win !== false)
$win->onload = 'my_onload';
</script>
So, the reason why people ask such questions is not that they don't know how PHP works. It is because they don't understand web technology in general. They fail at point, which requires understanding of what, where and why is supposed to be executed.
The PHP compiler executes in the server as a CGI script. A CGI script reads from Standard Input and writes to Standard Output, similar to a console or command prompt program. The PHP compiler reads the file containing HTML and embedded PHP and writes the HTML out and (when encountered) executes the PHP and writes the result of the PHP code. The output is received by the server then sent to the client.
See PHP: CGI and command line setups - Manual that says:
By default, PHP is built as both a CLI and CGI program, which can be used for CGI processing.
The difference between CLI and CGI are insignificant here.
Also see PHP: What is PHP? - Manual that says:
the code is executed on the server, generating HTML which is then sent to the client.
See RFC 3875 - The Common Gateway Interface (CGI) Version 1.1. It is the official definition of CGI. PHP seldom uses the original CGI protocol; other protocols such as FastCGI are used and perform the same function as the original CGI protocol but are designed to be more efficient. For the purpose of understanding how PHP works the original CGI protocol is relevant. The following is an excerpt of the RFC.
Abstract
The Common Gateway Interface (CGI) is a simple interface for running
external programs, software or gateways under an information server
in a platform-independent manner. Currently, the supported information
servers are HTTP servers.