Should I use PHP or PHP + Java EE? - php

I'm going to start a new project with instant message support.
I find that there is no good long polling solution in PHP, but there is some good ones in Java EE.
I'm wondering if I can integrate PHP and Java EE to get the function? Or should I just use Java EE instead of PHP?

Keeping the number of development platforms to a minimum is always a good idea. It will keep deployment requirements low, gives less operational complexity and gives the best possible integration.
If you want to replace PHP by Java, you have lots of frameworks you can use to replace PHP. A good option would be the Stripes framework it’s an easy to use MVC framework that does not need much configuration.
An other very workable solution would be using Java in the backend for filling the database. And use PHP in the frond-end and use the database to retrieve data. This way the integration is limited to a shared database.
If you would like to have a direct integration between PHP and Java, things start to get more complex. It could be implemented by either web services or the faster php-java-bridge. But I don’t think you need this and if you do, I would seriously consider migrating the whole project to Java.
For an implementation example of the php-java-bridge see: How to share session between Java and PHP

You CAN build your application with PHP together with Java EE. The PHP is to generate HTML, and Java EE supports Comet.
Actually, Facebook generates HTML with Apache server. I bet Facebook web pages are written in PHP. And the Comet server of chatting is written in ErLang hosted in Mochiweb. Two languages & servers works fine together.
The decision is up to your own preference.

Related

Web programming Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm a amateur developer with a little experience in PHP.
I recently learnt Python, I've to admit that it is awesome as a programming language and its great libraries, but using that for web development seems to be a big pain in the ass. As far as what i read, I've to use CGI, mod_wsgi, etc. to deploy (http://docs.python.org/howto/webservers.html), Restart the server to see the changes (http://stackoverflow.com/questions/581038/python-web-programming)
My question is, Python being used so widely for web development, Why cant it be as simple as PHP?
ie i would love to write index.py:
print """
<html>
<head>
<title>Hello world</title>
</head>
<body>
Hello world
</body>
</html>"""
First to your question on why Python isn't as easy for web development as PHP: It hasn't been designed for it. PHP has had a lot of work towards making it a good language to write HTML pages in, including mod_php for apache. Python, while it is a very capable web language, it is also capable of far more than PHP. For example, the majority of Dropbox's software, both the desktop client and the server side code is Python. I use Python in my day job and have used it to integrate legacy C code into new Python code via Cython.
Moving on. There are a number of Python frameworks out there that can make your web development experience far less complicated. 2 of note that are widely used professionally and by hobbyists are Django and Pyramid (formerly Pylons). As a new user I'd recommend you start with Django, it's a great way to get started and can be used for large and complex sites (and more) as your experience grows.
You will find that Django and Pyramid include "development servers". These are web servers written in Python that are packaged with the frameworks to enable faster development. Using these development servers you can get up and running very quickly.
There are also pure Python web servers that are infact incredibly fast, robust and very production ready. To deploy a Pyramid application on Gunicorn, a very good Python server, only takes a couple of extra lines in your Pyramid configuration. Typically you would reverse proxy to these pure Python servers via Apache or Nginx.
If you want to go the Apache server route, you just need mod_wsgi. Serving a Python site with mod_python or as a CGI is a somewhat outdated way of doing it. WSGI defines a standard for Python to handle web requests so mod_wsgi enables apache to pass requests to your Python application in the expected format.
When it comes to deploying Python to a hosting provider, you have to look a little further than you would for PHP hosting, but there is a good list maintained on the official Python wiki. The 4 links at the bottom provided different lists to meet your requirements.
[If] Python being used so widely for web development, Why cant it be as simple as PHP? ie i would love to write index.py...
Python can be as simple as PHP, as per your example. The simplest way to make the above work is to use CGI (and call your file index.cgi rather than index.py, then your script will work just fine. Though you should really specify the content type first, like this:
print 'Content-type: text/html'
This would apply in PHP as much as Python. Python's CGI module will get you up and running very quickly.
As far as what i read, I've to use CGI, mod_wsgi, etc. to deploy
You would normally choose one or the other, and realistically you would most likely choose a framework which is based on the more modern WSGI and not worry about the low-level stuff. But if you don't want to, you don't need to bother with these low-level interfaces.
Restart the server to see the changes
Probably not. Having to restart the server is a limitation of the framework and deployment configuration, and is typically not required. If you use mod_python this may apply, but generally not (many frameworks support auto-reloading, for example).
Python has a great wealth of resources for web development. There are bare-bones systems (eg. CGI, mod_wsgi), lightweight systems (eg. CherryPy) and entire frameworks (eg. Zope). You can choose one that best suits your needs.
Being able to create a simple file and produce some output might help get something going quickly, but it is not really a sign of a rich, mature, featureful framework. Sure, you can start displaying something straight away, but what then? All of a sudden you will need to either import or write all the same sorts of functionality that web frameworks provide. For a non-trivial web app, you need non-trivial framework.
For example, something like Django will give you a persistence framework, auto-generated admin interface, a tempting language, URL dispatch system, and much more. You can focus on your app logic, and not worry about the lower level details. Django is a good place to start, as it has great documentation and the tutorial will get you going very quickly.
As others have said, google "python web framework". There are quite a few, they are all quite different. To get you started the fastest (hours), I'd look at bottle.py.
Python being used so widely for web development, Why cant it be as simple as PHP?
Because Hello World don't scale. Because Python ain't PHP. From wikipedia[1] [2]:
Python is a general-purpose, high-level programming language
PHP is a general-purpose server-side scripting language originally designed for Web development
Python is great, python is DRY friendly. Unfortunately, when it comes to web developement, DRY isn't enough. If you actually want to get things done (efficiently): don't reinvent the wheel. That was pretty well summarized here:
What seems the biggest shame to me is that everyone is currently rebuilding this stuff over and over again and rationalizing it as some sort of secret sauce competitive advantage when it’s really infrastructure – stuff that really should be standardized so you can actually get around to doing the new and interesting stuff.
So, use the right tool for the right job, if you go the python way:
use python and
use a web framework, Django is great (or another one)
reuse packages, browse them at django-packages
maybe use a "meta-framework" like Pinax to get started
use Twitter Bootstrap as an UI framework
use a PaaS like Heroku to deploy (or another one)
Yeah it's more complicated than a hello world but remember there ain't no such thing as a free lunch. You're an amateur developer, you're not a professional coder and a sysadmin and a database admin and a designer and a system architect, etc. Don't be too shy to stand on the shoulders of giants because now, it's free. Please, don't build nothing less than a modern web app.
Also, PHP isn't anymore popular as it was [1][2], cf. PHP's fractal bad design, PHP hammer, etc.
PHP was solely meant for web application development, to be more precise for building Personal Home Page(s) (thats where P, H and P came). Python on the other hand is a general purpose programming language. It was meant for a whole lot of things (and had to include all sorts of batteries for all sorts of tasks). So, please do not expect Python to behave the same way PHP does.
Stand alone python scripts will require quite a bit of efforts to run. I would suggest to pickup a web framework. You might want to learn django (https://www.djangoproject.com/) to begin with. You might also want to give Google App Engine a try. Besides heroku, dotcloud, nuagehq and other cloud hosts make python (and django) deployment very simple and easy.
Hope you'd enjoy developing web apps with Python! :)

Is Haxe really good for php-targetting server side development?

I have such a conception, to build a simple web application using some php/mysql hosting service. I'd also like to create a local version of that app. The local version should work similarly as the online one (i.d. using browser as the ui) and have the ability to communicate with the server. I want it to be as lightweight as possible.
Professionally, I'm a c#/.net programmer. I also have some experience with c/c++,javascript, python and java. I know very little about php, and honestly, I don't like the feeling coding in that language, hence, don't have much willingness to dig into it. .Net, python or java they're all too unwieldy, I can't force the users to install any of them. So I thought about haxe's multi-targeting. If I were to code the project in haxe (it seems pretty straight forward to learn, for some one with my background), I might use the same logic on both side of the server and the client, by targeting both php and neko.
As a novice, I have some doubts. I'm not sure if haxe for php alreadly mature enough for this kinda job. I know haxe is a cousin of ActionScript, it primarily targets AS, and because the author is also the inventor of nekoVM, therefore, these two targets should be fine. But uh, how about php? Is it really good for that as well? Any hints or suggestions? Is haxe's builtin libraries ok for a simple web app or should I use a framework? Does neko have a httpRequest functionality at all?
Much gratitude in advance.
The straight answer is that Haxe/PHP seems to really fit well for you. That because of you background. I used Haxe/PHP in several projects (it happens that I am also its author) and speed has never been an issue for me. If there are bottlenecks usually there are also ways to optimize those portions for better performances, and if in the end you application scales to billions of users you can always opt to switch to neko or a C++/cgi combo.
About the frameworks there are a few options too: Web "frameworks" for Haxe to deploy in a PHP environment?

What non-OO language can a web dev use to create a one-off desktop app?

I'm looking to develop a Win32 desktop app - a one off, for a personal need. A GUI is not scrictly needed, though would be a bonus.
What is needed:
The ability to monitor the window title of a specific window.
The ability to run DOS commands when this window title changes.
I hope my programming ability is up to this - I feel I'm pretty good with PHP, but I'm not ready to spend time learning OO for this one-off project.
What non OO (or at least not mandatorily OO) languages are there for desktop apps that might be suitable for a beginner on a task like?
Any other, more hacky approaches are welcome too - batch scripts etc.
Many thanks for any advice,
Jack
Whether or not the language supports OO doesn't really matter for your purposes. After all, PHP supports objects and you seem to do just fine with it.
Personally, i'd recommend Java or C# to get started with. The communities for these two languages are huge and there are plenty of tutorials online to help you get started.
It's extremely easy to get starting writing C# with Visual Studio Express. And a good hello world tutorial.
Also, if you stick with C# you can take advantage of WMI which will allow you to do everything you need for this project (and much much more).
Lastly, most windows machines will be able to run your application without having to install anything extra and Visual Studio builds the .exe for you as part of the build process.
You can use PHP for desktop apps if you really want to. Just install the php CLI.
You can even do a gui for your desktop app in php: http://gtk.php.net/
EDIT: I'm not sure how easily you can call win32 api functions from PHP, however. There look to be a few articles about this online and a SO question: How to call winapi functions from PHP?
I would vote for Python using the included TkInter module for GUI. Dead simple to use.
Widgets aren't the prettiest looking, but development is rapid.
EDIT: I mistook "non-OO" in the question for "OO". Python is most definitely not "non-OO", but but is very well suited to doing what you asked.
You could write this in pretty much any mainstream language supported by Windows. C or C++ are obvious choices. C# and Visual Basic .NET are going to require the .NET Framework ... not a bad thing, but perhaps more than you want to tackle for a simple project. Come to think of it, you might be able to do this with JScript or VBScript, although I'm not clear on what API functions you have easy access to. And I have to believe that it's possible to do with PowerShell with just a little work.
Your options are wide open.
F#
It's an awesome piece of work, has access to the Framework class libraries, supports GUI development, really easy parallel programming, compiles to IL (same as C#) but has a really concise functional syntax.

PHP part in Python based website

I need to write a small addition to a Python+Django based website, hosted on Google Apps. Trouble is that I don't have any experience with Python.
The addition is pretty straight forward, it requires little database access
So thought of 2 possible solution's:
Quickly dive into Python and get it done with Python.
Run PHP on Quercus and write this particular addition in PHP, then somehow combine it into the website as a dingle PHP page.
Edit: There is another option I thought of:
Writing it in PHP and hosting it on an external server, embedding it in an iframe. The addition I am writing has no need to be SEO friendly, so an iframe will have no negative effect on the website.
What do you suggest?
I am not sure about how you will run php on GAE since it only support Java and Python.
I'd go with solution 1. Python isn't hard to apprehend, you should find ready-to-go code snippets in GAE documentation, and its Datastore doesn't seem too hard to use :D
there's a nice tutorial in GAE documentation: here
Quercus on App Engine runs on the Java runtime, while Python runs on, er, the Python runtime. While you can run one app with multiple runtimes, they have to be different major versions, which means that communication between them will be awkward - you'd have to make URLFetches between them.
I think you'll find it's far simpler to learn enough Python to make the changes. And trust me, you won't regret learning Python. ;)

implement Comet with erlang and use it for PHP application

I'm building a PHP web application and I've reached a point that I need to build a Comet server because I need to update my users' whenever a new data is available (pretty much like FB). I've spent so much time searching the web and I've come to a conclusion that the best way to build Comet server is to build it with erlang. Also I've found that apache-php is not a good combination for doing that because the process per request issue.So, I have to build a lightweight http server for comet application.
I'm totally newbie in erlang world but I'm thinking of implementing Comet server in erlang and make it to function as interface for updating the clients only. For the rest of my web application functions, I still want to continue implementing them with PHP. So directing the requests of updating the clients to the erlang server and directing the other requests to apache-php server.
It seems very complicating. I need to know what's the best way to learn erlang for the sake of building Comet server and how to combine the two languages (erlang and php) to work together like when I have new info. to be pushed to the clients, I need to make the new changes available to Comet and then it pushes the info to the users. So how can I benefit from php and erlang and make them work together.
Sorry for the long explanation but I really need your help guys and any guidance you may give me to learn and implement what I want. Thanks a lot in advance.
EDIT:
Should I consider learning Python and Twisted to accomplish what I want?
It's definitely possible to do this with Erlang. One possibility would be to use long polling, which you can do with mochiweb. http://code.google.com/p/mochiweb/
Another idea is to use sockets. Until web sockets are supported by a reasonable number of browsers, you'll have to use a flash "bridge" to create a TCP connection, and use javascript to communicate with the server. Take a look at web socket JS: http://github.com/gimite/web-socket-js
Once you have this set up, you can communicate between your Erlang processes and PHP with something like this: http://www.math-hat.com/~zukerman/projects/php-erlang/
Then again, if you're still a newbie to Erlang, maybe you'll save time in the long run with Python and Twisted or Tornado.
Apache+php is indeed a bad technology for comet style applications. You can use a lot of other technologies that are closer to php though: Ruby, Python and Perl should all be usable. If you really want, you could probably write some kind of socket server in php aswell, but I would probably not bet on getting it to work out. That's not to say that Erlang isn't a good choice, but there are more mainstream alternatives.
If you don't want to use a mainstream language, be sure also to check out node.js, which runs some very impressive benchmarks. Plus you may already know a bit of javascript.
You can learn Erlang pretty quickly, you should be able to use things like gen_server, gen_event and that sort of thing from OTP. The quickest way to learn Erlang should be to work your way through the documentation and examples at: http://www.erlang.org/doc/index.html.
For the communication between PHP and Erlang you can use sockets, fsockopen() and the rest on the PHP side and gen_tcp on the Erlang side. You can parse the Erlang terms sent trough the pipe from the PHP side (more info here).
I never used Erlang and PHP but I used Erlang and Python with some success, knowing PHP it should be pretty easy, just try to keep everything clean and keep the state on the Erlang side, using PHP only to generate the UI.
If you are considering Python and Twisted you can take a look at Orbited. They have very mature Comet implementation. You can make Orbited to communicate with your PHP application through STOMP protocol.
This article has a decent tutorial which will get you started with Orbited
http://thingsilearned.com/2009/06/09/starting-out-with-comet-orbited-part-1/
To integrate your application with PHP you will need to google for PHP STOMP clients
An addtional option is to use Nginx and it's push module (http://pushmodule.slact.net/)
This will allow you to use Comet from PHP without the need to learn a new language.
You should look into Yaws. It's an Erlang web server that's been around for over a decade, is extremely stable and still under active development and maintenance, and supports long-polling, PHP applications, WebSockets, and much much more — pretty much everything you could want.
The Yaws sources are on github and its mailing list is here.
Try Chicago Boss framework here ... using that you don't have to know the nuts and bolts of the thing called OTP (which actually very easy, powerful and battle proved), because the designer of Chicago Boss, managed to encapsulate it nicely... according to the tutorial.
I'm learning it right now, after learning OTP.

Categories