PHP part in Python based website - php

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. ;)

Related

PHP: possible to compile a web-application into a windows application?

I have developed a PHP web application, but a client insists on a real Windows application, since he doesn't like running the software inside a browser.
Are there any solutions for this, any compilers to turn a web project into a Windows exe ?
I have looked at Phc-Win , but that seems more suited for small command line utils, not for entire web-applications...
UPDATE:
just found this myself, both look quite promising...
http://www.zzee.com/phpexe/
http://www.exeoutput.com/index.php
There's no tool for this, short of a simple wrapper app that embeds a browser inside an otherwise normal application window. Your PHP app would have to be completely re-written to include ALL of the overhead code necessary to build a GUI - basically all the 'display' stuff that a browser does automatically, would have to added to your app.
Well some of you did not google good enough:
http://www.appcelerator.com/products/titanium-cross-platform-application-development/
Supports most of the "web-languages" to write native Applications.
Tutorial Reference for Appcelerator: http://appceleratortitanium.com/tutorials/3-appcelerator-titanium-tutorial-beginners.html
Quote:
"Q: What languages can I use to make desktop apps?
A: Javascript, PHP, Python, Ruby, HTML, HTML5, and CSS."
Not exactly what you are looking for: http://www.roadsend.co/home/index.php?pageID=compiler
You may look into "HipHop" (made by Facebook): Converts PHP to compileable C++-
There's a tool for this. :-) I never used it but you can try this: Winbinder.
It is simple to compile your PHP source code into an executable. Facebook released a compiler for PHP in early-2010, called HipHop, which aims to create C++. You could then compile this code, for example using gcc, to machine-code.
The more difficult point for a complex Web-App like yours is the user interface. When compiling the way I described above, the application can be run from command line - this might work for simple tasks, but not, if your application returns HTML.
One possibility to solve this problem is PHP-GTK. PHP-GTK is a API for GTK (the graphical user interface used by Linux Ubuntu by default), written in PHP. Using this solution would have to read some documentation about this API, and you would need to rewrite some parts of your program, but it would probably be the most beautiful solution, because it would create a "native" experience.
Another possible solution could involve Adobe AIR, which lets your create programs for the desktop, using HTML, CSS and JavaScript, but I don't know if and how this would work together with your compiled PHP.
Please also note that it isn't absolutely necessary to compile your PHP for it to run on the client's computer; You could also ship the PHP-interperter right with your (uncompiled) PHP-script. Of course, compiling brings benefits, such as faster execution of the program.
-- André

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?

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

Python or PHP for small windows administration scripts?

I'm choosing between these two languages, in contrast to another question here. My program going to be set of scripts checking files, free space, checking that apps are running etc. and writing information to database. Then PHP web page will show results.
Python have more examples of winapi calls (at least at StackOverflow) and more attractive to learn and use in different areas of programming, but I didn't use it before. With PHP I have small experience and I will be using it for results web page anyway.
PHP seems to be easier to install on network (to use one network installation for many workstations). Both languages can work with COM objects (I will need ADO).
Scripts will be small, not complex, but their number will grow.
Can someone with experience in similar tasks advise on choice between these two?
Don't shrink from using a language just because you haven't used it before. Learning a new language is one of ways to expand your overall capabilities as a programmer. True, you won't be as productive with it at first but learning how the language tackles common problems (manipulation of data structures, creation and lifetime of objects, etc.) will teach you new ways to think about computing.
That said, I would suggest you use the ActiveState version of Python (http://www.activestate.com/). It has the Windows integration included. I'm not sure about network install with Python. I've installed it across a net by running a remote desktop of the target and running the installer. Windows wants things registered in the registry so running a language is not like running an .exe sitting on a remote file share.
I asked question first time as anonymous so have no other option to reply now except to write an answer.
Thank you verisimilidude for ActivePython advice!
Installed ActivePython at home, reading Dive into Python 3.
Installed RadPHP XE at work (company bought it).
So for work it will be PHP. For me, if have free time (and may be for kids, when grew and if interested) it will be Python.
As someone who uses both on a regular basis, I tend toward using python for windows scripting and php for web apps. It's mostly just my preference, but I think they're each ideally suited toward different things. I love using Python in windows, it is really versatile.
a ) python is a nice alternative because you can generate an executable, otherwise (running as script) php is more suitable because it does not required an installation.
b ) try to not to connect directly to the database. Instead, you can create a web page then the clients can connect to it instead to do a direct connection to the database.
for example in php (in the client)
$fp=fopen("http://192.168.0.200/update?id=mymachine&value=200","r");
fclose($fp);
ps: For api calls, both (php and python) can do the same. Thought, for php and Windows Vista (and higher) exist some restriction when you are running it as a apache-module and apache is running as a service but i don't think it is the case.

Should I use PHP or PHP + Java EE?

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.

Categories