What purpose does a python backend serve? - php

I am primarily a PHP developer, and I have been browsing the source code of a few open-source applications recently(Mozilla Bespin in particular), to find that some of them use a Python "back-end." I was just wondering what the purpose of this back-end is. I am assuming it is the same thing as the model in an MVC framework and is used to interface with the database, but I'm unsure. If I'm right and the back-end is used to simply interface with the database, is the sqlite/mysql server included in the backend, because I didn't see any database config information in the install directions?

A "Python backend" is simply server-side software written in Python, no different in general terms than server-side software written in PHP. It does all the same things, just with a different programming language.

It looks like Bespin uses Python in the same way it would use PHP, if the autors chose PHP and not Python.
If you are a PHP developer, you already are a "back-end" programmer and you already know what it does, the only difference is the programming language that was used to do that.
Some web sites, mostly the huge ones like Facebook or Twitter, consist of more layers than the usual MVC ones. If you look at Facebook, you can see PHP scripts that generate HTML and AJAX responses as the "front-end" and high-performance databases, storage, computation cluster, application servers etc. as the "back-end" (where PHP is rarely used). So what is considered "front-end" and what "back-end" may also depend on how you look at it.

Related

Two ways to make python based webpages?

I wanted to try out python to create webpages instead of using php. However I came across that you need either mod_python or mod_wsgi installed to apache to make it play with python. If you now use pure, i'm not sure if it should be said pure, python code, not using any web frameworks like django. I found out that making a simple page looks differently in mod_python and in mod_wsgi.
How come?, the more I looked into python it just seemed to be a harder language to use to make webpages comparing it to php. Is there some good starting point to learn python webdevelopment?
Sorry if my question is blurry. I simply want some guidance to start out with python webdevelopment
Yes, making a webpage with python without using a web framework is harder than it is in php. This is by design, since it gives you a great deal more control over how your page interacts with the server, allowing you to build sites that scale well, among other benefits. WSGI is the modern way to interact with a server, but as you observed, it includes many of the nuts and bolts that PHP hides from the user.
If you're looking for a php-like experience for python, you might look at web.py or Flask. They are pretty minimalistic as far as frameworks go, and take care of interacting with the server but otherwise stay out of your way.
That said, you really should consider Django or another similar framework - they provide some really great benefits that help you get what would otherwise be painfully complex sites going quickly. They solve a slightly different problem and provide different solutions from the common PHP frameworks, so you should consider them even if you don't like frameworks in PHP.
If you want to do things in an even more php-like fashion, you could use CGI. It's definitely not a recommended solution, and won't teach you best practices moving forward, but it can get you started...
Really though, consider a framework. It's how most development in Python for the web is done, and you'll learn more useful skills if you develop using one.
mod_wsgi is better, because it's based on the WSGI specification, which defines the interface between web applications (or frameworks) and web servers. A WSGI app at its simplest is nothing more than a function that sends some HTTP headers via a callback and returns a string in response to information about an HTTP request. And since WSGI is implemented by many web servers, you aren't tied to Apache.
The closest you can get to pure frameworkless web development in Python is to write the WSGI app directly. This will really help you see the things that a framework like Django will obscure.
To make things easier, you might consider using Werkzeug, which is a utility library for WSGI. It has many components that are framework-like, but you can choose which ones you want and which ones you don't. For example, it has a really neat system for parsing and dispatching URLs. Werkzeug also has a simple command-line WSGI server which is probably better for development than Apache.
I'm replying to you with some advice, as someone who was in a very similar situation as you just a few months ago.
So you're using apache to host your website. That's cool. To make python play nice with apache, you're going to want to use mod_wsgi, for the reasons others have stated: seperation of concerns makes it better than cgi and mod_python is no longer being supported.
However, your impression that foregoing a framework will bring you closer to programming in "pure" python is a little bit off the mark. I shared the same opinion, and experimented with both Django and using only mod_wsgi. Let me share what I found.
Mod_wsgi is an implementation of the WSGI standard found in PEP 333. The distinction between the implementation and the standard is important. First, because it means that WSGI compliant applications will work across implementations. More importantly, it reveals something important about what WSGI is meant to do. That is, WSGI is intended a standard for writing frameworks. From the PEP:
simplicity of implementation for a framework author is not the same thing as ease of use for a web application author
and
The goal of WSGI is to facilitate easy interconnection of existing servers and applications or frameworks, not to create a new web framework.
I'm not saying that you shouldn't do something with wsgi, but you should expect to be writing a framework more than an application. If you're interested in writing a simple framework this tutorial is where I started.
However, if you're just looking to make a website, look into one of the frameworks that others have suggested. You'll still be writing python code, but the authors have worked hard to make the code you write closer connected producing websites than producing frameworks. I've personally used Django, and once it was up and running, it was rather painless to churn out interesting applications. Also, their documentation is very good, and they have a good tutorial here. That being said, Django is very fully featured, and if you're looking for something a little more minimalistic, I've heard good things about Flask, but there are lots of other options as well.
You can use ordinary CGI, which is really simple. Create a Python program that looks something like this:
#!/usr/bin/env python
import sys
sys.stdout.write("Content-type: text/html\r\n\r\n")
print("Hello <em>world</em>!")
Make this file executable (chmod +x) and put it in a directory you've configured for CGI files in your web server.
You will also find the standard Python cgi module very helpful.
If your goal is for making your python program web friendly then the answer is Cherrypy. It is a very flexible and simple framework that enables your python objects exposed in web. Check it out and it has a nice web server built-in that you don't need apache/mod_wsgi etc.,

BackOffice Database Application FrontEnd - Program in C#/VB.Net or PHP?

I'm working on a project where there will be a MySQL database containing data that will mostly be displayed on the web using PHP. However, there is a need here for a back-office data entry application (linked to the same MySQL database) that is feature rich and easy to use.
what I'm trying to understand is where we are at with web-based frontends. I find that there are still so many events and features that I can make use of in a Windows Desktop GUI written in something like C#, VB.Net or MS Access. I don't have a lot of experience programming UI for web but it's my impression that it's still more difficult and takes longer to get similar or the same functionality using non-MS web technologies (I dislike ASP.net, sorry) as compared to programming the desktop portion in a traditional desktop application language like C#, VB.Net, or MS Access.
jQuery and jQuery UI are definately making things easier. Also, there's very rich online applications like Google Docs and Zoho but it's my impression that these are programmed by some of the top web UI programmers around, not to mention that it takes longer to write it and intensive testing to make it work in all of your target browsers. It also takes extra time and code to "block" browsers that don't meet the requirements.
What programming language would you recommend?
I know I may not have given enough information here but I'm not sure what I'm missing. If you have questions just leave a comment below so I can edit this post and answer the questions.
I think, the important decisive parameter in your case is:
who is going to use the end?
TRUE: almost anything can be implemented as a web application these days and web applications are the future while desktop applications will become the exception
TRUE: the obvious challenges of the web are still the same
In your case, if the end you're talking about is for internal use and just a few selected persons are going to use it plus you are more fluent in desktop application development... the choice seems obvious to me.
If on the other hand there is a chance that a bigger number of people in many locations with different computer systems are going to use the end, make it for the web.
You say you know VB.NET, well where's the problem... you can write your aspx pages in VB.NET, can't you?

Perl vs. PHP to tar files on a remote server then move them to another remote server

I need to create a web application that tars files on a remote server then moves those files to another server. I am new to scripting languages and was wondering if there are advantages to php or perl for this type of application.
Not really. Both will get the job done just as good as the other. The bottleneck of both will be connecting to the remote server.
PHP was originally derived from Perl, so the syntax between the two are very similar. It's all a matter of taste.
PHP is nice because many Apache servers are setup to allow you to embed PHP code inside your HTML pages. This makes PHP very popular in building things like CMS systems and bulletin boards.
I personally think that the PHP syntax is sloppy. There's way too many specific functions and they're not clearly thought out. The syntax changes from one function to another. I guess it's part of PHP's group based philosophy where a lot of people add a lot of features. I also like Perl's use strict and use warnings pragmas which I find save me a lot of grief.
But, as I said, when it comes to webpage development, PHP is ahead of Perl.
(Yes, I know about modperl, but that's not usually installed in most Apache servers).
I'd say to go ahead and learn both. I believe the Perl books are some of the best written programming guides I've seen. I haven't been too thrilled with the PHP ones. Maybe its because Perl is just more established, so the documentation has been better defined.
Then again, if you're going to learn something, maybe you should try Python. I'm not a fan of Python, but its the up and coming language that most people are learning these days. Google uses Python extensively. And, don't forget Ruby which has the webbased Rails platform that's very popular.
By the way, what you want to do isn't part of the default language, but most languages have modules that are easily installable. For example, you'll need Archive::Tar and LWP for Perl. These can be downloaded from the CPAN module archive.
It's going to take you a while to pick up enough of any language to do what you want, so be patient and have fun.
You need this ssh extension http://php.net/manual/en/book.ssh2.php
It support calling ssh using ssh2_connect.
And you can bundle with tar, scp, or even rsync

How much languages is "recommended" for a dynamic website?

When constructing a website, say a Q&A site or a just a forum site for a community, is just knowing HTML,CSS,PHP, MySQL, and javascript enough to make the site dynamic?
I am saying this because when I talked with my teacher, he said that major sites use many languages combined. And he said that a site shouldn't be designed only in PHP.
So is it possible to create a good website, not e-commerce, with only html,css, and php?
yes. there is no reason you should use more than one language internally. it makes making it all work together much easier in a server environment, where the extra load of IPC over function calls can slow things down considerably.
Ofc! :)
Lots of large/enterprise portals use only HTML, CSS, Javascript, PHP & MySQL.
But don't forget that there's always a right tool for the right job... A simple site (even an e-commerce) will run very well on PHP & MySQL.
Short answer: yes, it is possible.
Longer answer...
HTML, CSS, PHP and MySQL are already many languages, but I guess he means that most major sites have a heterogeneous back-end. This is probably not out of choice though -- more often it is historical. As people change and new technologies emerge, new pieces are built with different languages and frameworks.
I have built a forum and Q&A sites with HTML+CSS+PHP+MySQL and many other people have done the same, so this set of tools is without a doubt adequate for building something like this. In fact, I would argue that you could build almost anything on the web with that combination.
A more interesting question (that will generate more heated response) is what framework you use on top of that. A CMS like Wordpress of Drupal, or an MVC framework like Zend, CakePHP or CodeIgniter.
Or whether you should be dropping PHP entirely and using something like Django or Ruby on Rails. Knowing more than PHP will definitely help you to be ready for newer approaches.
The dynamism of a website comes from a server side language that can create a HTML output on the fly, that's it. You can add a DB, simple JS or AJAX, but those are merely optionals.
Now, as for your teacher, languages like PHP, Python and ASP are, in the end, the same. It's ridiculous to have the includes files in ASP, the main files in PHP and the configuration files in Python, that makes absolutely no sense. Maybe, hopefully, he was talking about using JS in conjunction with PHP and SQL which is a natural recommendation.
The fact that your teacher is obsessed with another technology doesn't mean that you can't work with PHP only.
As the others said, it is perfectly reasonable and possible.
(I'm personally obsessed with ASP.NET, but still, I won't say that it is the only way to go for everyone. And PHP is just geat for beginners.)
Is he referring to the front-end or back-end?
The front-end of a website - the part that the user sees and interacts with - must be written in HTML.
(It may optionally include CSS and Javascript to enhance it.)
The back-end is what generates the front-end, and also determines the structure and control-flow of the application.
There's absolutely no need to use more than one language for the back-end, and it's often simpler to stick to one language.
However, for the front-end, you have no choice but to use HTML; otherwise it isn't a web application.
The front end must output HTML. These days it should use CSS for formatting. It will likely use Javascript to provide client side capability. Requiring javascript will likely create accessability issues for some users.
PHP is one of several languages used to handle requests. It is in interpreted language requiring the source be placed on the server. This opens up significant security risk if the someone gets access to the server. Several hosting sites have had major problems with PHP based sites over the last few weeks.
Java is run in a compiled form and code is not required to be on the server. This provides a layer of security as it is not simple to modify the code. Java runs in a container, and usually a framework. Developing using the Spring framework in a Tomcat container is an option. The learning curve is higher than with PHP. It also has strong support for accessing remote resources which allows it to integrate with legacy applications.
With any of the languages, there is a risk that developers will use available functionality when they shouldn't. The Java J2EE model is appropropriate for some sites, but was often implemented because it was the fashion, and there are a lot of tutorials on using it.

Does PHP compile data?

I'm a student learning PHP. I basically make the stuff work, but never wondered about how the php.exe(on windows) works.
Does it compile the stuff it has to handle or not?
Reason I'm asking is because someone told me that ASP.NET has to compile all website-dependant data is has/receives, like everything that gets uploaded through a form.
He claimed that PHP is faster on that subject, since it does not have to compile anything.
I can't find any good information on either subjects, so I'm asking here.
PHP is a scripting language, and so is not compiled as such. It is parsed into an interal representation which is in turn "run" by the PHP runtime.
Your friend is correct in so far as that ASP.NET is compiled. However, it's only the actual program instructions that are compiled, not data. The way PHP and ASP.NET treat incoming (and outgoing) data are pretty similar in principle. If anything, ASP.NET will be faster than PHP because it is compiled, since compiled code generally runs faster.
As #chaos has said, ASP.NET does not "compile" data received through a form.
Most likely what your associate is referring to is called ViewState in ASP.NET, and if that's that he's talking about, he's correct, although he mislabeled it as "compiling". ViewState does encode and store the state of the form and the server does need to decode this data and apply it to the object model. It uses this information to raise events that programmers can hook server-side, providing a much richer model for programming.
And, yes, this is a performance hit. PHP can be faster than ASP.NET; I've worked as a PHP developer and as an ASP.NET developer and I can attest to this.
But performance is not everything--more time is spent in data transit than it is in processing on a web server for all but a very few niche cases. And there are other aspects of your system that matter more than raw pushing power. ASP.NET trades that raw performance for other things.
This is where ASP.NET shines and PHP fails horribly. PHP cannot offer nearly the capability of ASP.NET for things like modularity, maintainability, security, re-usability, and general base library capability. Yes, PHP can be faster than ASP.NET. But ASP.NET is still superior.
Of course, ASP.NET sucks, too, IMO, but that's more because of some design decisions that I frankly disagree with. But I'd much rather use it that PHP any day of the week.
Neither PHP nor ASP.NET normally compile (interpret as program instructions and convert to executable code) data received through forms.
Possibly your associate may be confused about the difference between compilation and data sanitization, or something. I really don't know.
No. The type of data you are talking about is passed through to PHP as environment data from Apache. You can do it yourself with command line options to php.exe if you want.
Data is rarely compiled unless it is part of a resource for a program.
PHP itself is an interpreted language, which means that the code is never compiled into a machine-friendly format, it is simply scanned and parsed by the interpreter in order to be executed.
Tor Haugen is right, PHP is an interpreted language meaning the files remain as plain text on the sever and are interpreted as they are requested. ASP.Net is a bit of a hybrid because the *.aspx, *.ashx, *.ascx, etc. files are all interpreted while external libraries are compiled into DLL files that are then linked in like a normal desktop application. So if you have, for instance, several projects, one of which is an ASP.Net web application that relies on several class libraries, you would have several plain text files (web app files) and several DLL files that are generated and used by the server. You can use DLL files which PHP but it isn't as seamless. Usually such "class libraries" would simply be "included" as additional plain text files

Categories