Jump to content

Compiled languages and PHP


Synook

Recommended Posts

Note also that PHP is an interpreted language, it isn't compiled at any point (not even JIT, like Java) (unless you use a third-party compiler).--------------------Edit: This thread has been split from another, so we can discuss without getting very much off-topic. The "seed" post contains content on multiple topics and can be found at http://w3schools.invisionzone.com/index.ph...st&p=172873.

Link to comment
Share on other sites

Err, compiled languages are generally faster than interpreted ones. ASP is usually also interpreted, however.

Link to comment
Share on other sites

Ok, it must be ASP.NET then, that is compiled. I haven't really programmed in ASP.NET, but my experience with it was that my PHP version was faster.Interpreted languages don't have to compile, they just interprete so that should be faster right? I don't know.Anyway, this is getting off-topic..

Link to comment
Share on other sites

You only need to compile programs written in compiled languages once, then every time they run it just goes straight to memory. Only languages that utilise Just In Time compilation, like Java, compile every time a script is run. But yes, off-topic!

Link to comment
Share on other sites

Interpreted languages don't have to compile, they just interprete so that should be faster right?
You would think so, but compiled code is much, much faster. The reason code is compiled is so that it can be translated down to the machine code which the processor can execute natively. A processor cannot execute PHP code natively, so it needs to go through an interpreter to tell the processor what to do. Even though the compilation process takes some time, compiled code is much faster than code which needs to go through an interpreter. IE9, for example, will actually compile Javascript code before it executes it, so that when it executes it it does so much faster.
It makes me wonder why php.net still talks about 'compile-time'.
You're probably seeing references to compiling PHP itself, not your PHP code. You can download the source code for PHP written in C and compile PHP yourself, and there are various options you can use when you compile it to enable or disable certain features in PHP.
Link to comment
Share on other sites

  • 2 weeks later...
You're probably seeing references to compiling PHP itself, not your PHP code. (...)
I don't know what you mean by that, but does it include the following quote?"__NAMESPACE__; The name of the current namespace (case-sensitive). This constant is defined in compile-time (Added in PHP 5.3.0)."It probably doesn't mean my code is compiled, but it certainly implies so.Anyway, it doesn't matter. I just think PHP is faster, eventhough I may be misguided because I worked with heavy-duty ASP applications, as opposed to relatively simple PHP webpages.
Link to comment
Share on other sites

I'm not sure about the __NAMESPACE__ "constant", those constants change their value based on where they get used in your code so none of those should be defined when PHP gets compiled. An example of compiling PHP is on the MySQL extension page:http://www.php.net/manual/en/mysql.installation.phpThat describes how to build PHP with support for MySQL, so that you don't need to use the extension. If you compile PHP with support for MySQL, the MySQL extension will always be available regardless of whether or not the extension DLL file is enabled in php.ini:

For compiling, simply use the --with-mysql[=DIR] configuration option where the optional [DIR] points to the MySQL installation directory.
ASP.NET applications actually do get compiled. The first time you load an ASP.NET application, the server will compile all of the code. Every other time that application is loaded, it executes the compiled version. You may have heard of the common language runtime, or CLR. The CLR is the language that the application gets compiled to, which is actually what gets executed. Any of the languages that you can use to write .NET applications, from C# to VB to even PHP, will compile down to the CLR for the server to actually execute. If you're confused about that, it is in fact possible to write a .NET application using PHP. Someone took the time to write a compiler for it.
Link to comment
Share on other sites

So when a web server receives a request for a php script, is the separate application that processes the php called a container? I know in jsp and java, the container does all the processing of jsp's and java servlets.

Link to comment
Share on other sites

A program that takes a script and executes its commands without transforming it into native machine code is known as an interpreter. This is a standardised term, however Java also has a compiler that converts the high-level source code into special machine code that is then interpreted (or further compiled) by the Java Virtual Machine. The word "container" has no standard meaning in this process, however in JSP terminology it appears to refer to the server that initially receives the HTTP requests, like the role that Apache plays in an AMP stack.

Link to comment
Share on other sites

Oh ok. Trying to understand what a container baffled me for the longest time. I guess the difference is that when a user requests a php file, apache will process the file and send back html to the user. However, in jsp, if a user requests a jsp, the jsp is passed from a web server like apache to a container like tomcat which turns the jsp into a servlet, processes the servlet, and sends back an html file to the user. At least I think this is correct.

Link to comment
Share on other sites

Not exactly. When a PHP file is requested, the web server (be it Apache or another web server) passes the request to PHP, PHP processes the passed PHP file, and gives the result to the web server. The web server will then give the result to the client.Similarly, if JSP is requested, Apache sends the JSP file for processing, receives a result, and sends the result to the client. The only difference is that the road between the Apache passing and Apache receiving is a little longer.

Link to comment
Share on other sites

so since the container does the processing of jsp and servlets, would you say the container is the equivalent of PHP?
If "container" stands for Tomcat, or whatever receives the JSP, then I'd say yes.
Link to comment
Share on other sites

Tomcat is only the container for JSP and Java Servlets.PHP is a programming language. When you download the PHP package, it installs a command-line interpreter and an Apache module. This Apache module is what allows servers using Apache to understand scripts written in PHP.

Link to comment
Share on other sites

Tomcat is only the container for JSP and Java Servlets.PHP is a programming language. When you download the PHP package, it installs a command-line interpreter and an Apache module. This Apache module is what allows servers using Apache to understand scripts written in PHP.
ok so the apache module for php is basically the equivalent of a tomcat container for apache?
Link to comment
Share on other sites

Will you stop using the word "container" please?!? That's almost as abstract as the term "token".In case it isn't already cristally clear, I've drawn a diagram of the whole thing... I know you haven't asked, but I've also added MySQL, because we often have other people that fail to see how it fits into the pucture.

Link to comment
Share on other sites

thanks for the diagram. so what are steps 3 and 6? the module that routes to the php or jsp interpreter?Btw, I was using the word container because that's how it is referenced on the home site and in the head first jsp servlets book. But in any case, looks like it plays the same role as the php interpreter.

Link to comment
Share on other sites

thanks for the diagram. so what are steps 3 and 6? the module that routes to the php or jsp interpreter?
Yes.They load the interpreter at some point (when Apache starts, in the case of mod_jk or the Apache module from PHP; when the appropriate HTTP request arrives in the case of mod_cgi; at regular intervals in the case of mod_fcgi), and execute it when an appropriate HTTP request arrives.
Btw, I was using the word container because that's how it is referenced on the home site and in the head first jsp servlets book. But in any case, looks like it plays the same role as the php interpreter.
I've read up a little more, and it seems the term "container" may indeed be appropriate for Tomcat. Still, I'd suggest you use the term "servlet" in the future, because "container" is too abstract, whereas "servlet" commonly refers to "a JAVA-ish thingy that receives something and outputs something"... still somewhat abstract, but less.What Tomcat appears to be doing is compiling the JAVA code with the configured JAVA compiler, and execute it with the configured JAVA runtime. Because Tomcat is the one that receives a JSP file (even though it doesn't compile it), and is the one to output the final results, it acts as a "container" for the whole JSP process. In PHP, the whole thing is integrated into a single step.[i think I just created myself a summer project - make the diagram interactive, and extend it further]
Link to comment
Share on other sites

That's a lovely diagram.
You've said it all. Well done boen_robot, or should I say Vasil? :)One addition. You haven't included information about this, is it possible to route to JSP via PHP? Like, using both platforms for one website? I'd like to see Java on the web for myself, but don't want to loose PHP. I foresee I might be launching some Java within my php site, and so far the database is the only relation between them I know of.Also, I don't really know what makes JSP JSP, as opposed to just Java.
Link to comment
Share on other sites

You've said it all. Well done boen_robot, or should I say Vasil? :)
Whatever strikes you fancy :) There is sort of a way to link PHP and JAVA, but of course, it comes at a price - speed. JAVA code will always be executed faster in JSP files, while PHP will always be executed faster in PHP files.The PHP/JAVA Bridge is the thing you're looking for. What it basically does is to set up functions in PHP/JAVA, which when called, make a new HTTP request to the same server to a special JSP/PHP file, which calls the requested method/function/whatever, and returns its output, along with type information, as a response, which the internal function then converts accordingly.You can't get any deeper integration between PHP and JAVA than that... they're just too different platforms.As for what makes JSP something more than JAVA... AFAIK, in addition to executing JAVA code in a web app, and compiling it in the background (which, when you think about it, is a nice idea on its own), you can map JAVA code to tags (don't ask me how...), so that you could at one point write just the tag as if you (or whoever is the poor fellow) don't know JAVA, and execute the appropriate JAVA code.BTW, installing and configuring the PHP/JAVA Bridge is a pain... last time I tried at least. I only got it working once, after an hour or so of experimenting and searching around. I'm now with a new Windows install, and don't plan on putting myself into this ###### again for now.
Link to comment
Share on other sites

Ok, so I understand there is not so much integration/compatibility in PHP for Java, as that wouldn't be practically possible, that's good to know.I don't really understand what the bridge does or is. I do know you mean both java and php could actually communicate through this method, possibly with due speed loss, however that is a little too complicated thing for what I was really asking. My bad. What I really meant, simply, how do you request remote java execution from php, much like a query from MySQL? Not exactly litterally java-interpreted code within a php file or something like that; that would be too messy for me.Besides, I still know only of JSP as a Java manager on the web, what is it really, for a noob like me? I can do a lot with Java on an OS, like I have started building a beginners 3D game engine, but if Java meets the web, all I know is that I should look into JSP. Should I compare it to ASP.NET, which is like html with an embedded script, or is it a full script of its own like php? And can it do as much as Java on an OS, is it limited to a webhost's restrictions, do I need to learn a new language, is it different to Java at all?*Edit:However this is getting offtopic.. unless...:Am I right, and is JSP compiled, where PHP isn't? -ontopic

Link to comment
Share on other sites

Have you ever tried using JAVA from console? You know, the thing where you write something at a screen, and get some text on that screen as a result. If you know any JAVA, you've probably had. JSP works on the same principle - the standard output is the HTTP page, instead of the console screen. And instead of having only JAVA code, you have, yes, similarly to PHP and ASP.NET - HTML with embedded server side script. So, whatever you can do in a console, you can do the same in JSP.Yes, JSP is compiled in the backround (ot at least that what I gathered after reading some of what big dave posted), right after it detects that the JSP file has been created or modified, and the resulting JAVA bytecode is then cached, and executed when the appropriate JSP file is requested.And yes, PHP is not compiled at all. The interpreter "compiles" the code only when the PHP file is requested, and outputs the result at that point.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...