Is it possible to embed Python in PHP? - php

I work for a small tech start-up, and our main site is built on the CMS Drupal, which is a PHP-based CMS. However, I know some Python and would like to develop web applications to integrate with the website and allow users to interact with them.
How would I go about doing this? Does anyone have any experience or knowledge? Any particular module/script/etc that allows using Python or calling Python from PHP or Drupal?

If you are developing a web application nothing stops you from using Python and making it accessible from a subdomain or path not used by drupal, just have the web server point to it. Ex:
http://mainsite.com/ <- drupal
http://app.mainsite.com <- python web app
http://mainsite.com/python/ <- python web app
This is fairly straight-forward with most web servers. Django might be particularly well suited for this, it has a nice feature which can inspect live databases, and generate models for you:
python manage.py inspect.db > models.py
Which lets you interact with your existing database from Python with a nice ORM.
If you need to literally call Python from a PHP page, you can use zeromq for fast IPC or TCP communication, or build a simple REST API, etc.

There are several different ways to do integrate Drupal with external applications, but your best bet is probably installing the services module in Drupal, and make calls from your Python app over HTTP, just as you would interact with a remote server.
Some other options:
Interact directly with Drupal's database, rather risky as Drupal's database structure can change significantly with module upgrades or even configuration changes.
Place the Python app within an iframe of a Drupal page, giving you Drupal's design, though no functional integration.
Use JavaScript as a client-side middle-man between Drupal and Python.
Use command line as a server-side middle-man between Drupal and Python. Drush would be useful here.

Related

Ruby on Rails to PHP CodeIgniter

I have no experience in Ruby on Rails. I employed a developer to create a tour booking system for my site (php codeigniter). He developed it using Ruby on Rails in heroku and then linked to it by iframe in my front end.
Problem is
MS explorer doesnt display it,
issues with dynamic booking form sizing,
Cookies for the cart doesnt work as it's cross site and in iOS sometimes the security denies the cookies so system doesnt work,
Site massively slowed down due to the http requests.
Is there a way to convert the ruby system into php so i can just have it on my local site? Can anyone think of any other solution if not??
thanks
Unfortunately, there is not easy way to convert a language to another, with some exception (like language that compiles to another one, for example CoffeeScript to JavaScript). Using iframes will create security problems, which in turn trigger (modern) browser to block them.
So, what are your options?
Use the Ruby & Rails website as a subdomain of your main. Example, if your site runs on chambers.com and that the Ruby on Rails site is about invoicing, it could be on invoncing.chambers.com, and you could use links from one to the other
Rewrite either the Ruby or the PHP part, depending on size & team capability

Chrome Extension as GUI for JSON API

I'm working on some kind of a huge project using PHP which is a CRM and Smart Ticketing and Processing System for travel agencies and I'm planning to make it only available on chrome.
And I'm new to Chrome Extensions/Apps, But when i'm reading about creating extensions i surprised that i can create any html content with any JS codes included.
My questions are:
Can I include my application GUI with pure HTML && CSS && JavaScript in some extension and make it send/receive requests to my PHP-API Which already exist in my code since it's fully AJAX project?
And if this can be done; what do i have to create Google-Chrome-App or Google-Chrome-Extension And what is the difference between them and where to start reading about required solutions.
IF this can be done it will be perfect since the GUI elements (HTML, JS, CSS, Images, etc..) will be loaded from local store of each user/employee's machine and the only transferred data would be JSON requests.
Yes, you can create your GUI in pure HTML, CSS and JavaScript. This is actually the only way to make a GUI in Chrome extensions. Your PHP based API can certainly be accessed via an extension, if designed as a fairly typical client side accessible API.
Here's a brief description of Extensions and Packaged Apps:
Extensions are generally designed for augmenting the browser experience. For example, analyzing the pages the user is browsing and highlighting text. Chrome exposes several awesome APIs related to the browser and the browsing experience. However, it's just JavaScript, CSS and HTML, so it's definitely possible to take it a step further and create pretty much fully functional applications. However, there are no UI specific features in the Extension API that would make it easier to create a complex web app. This is not the purpose of Extensions. Look at the extension in the Chrome Web store to see some examples. Development documentation can be found here.
Chrome Packaged Apps allows you to develop a full blown desktop application using HTML, CSS and JavaScript. You can create complex applications with typical web technologies. This is a fairly new technology, but there's a lot of potential.
There is also the slightly confusing concept of a "Chrome App", which is really just a way to package a typical web application (or site) for display in the Chrome Web Store. This is not not really a development technology.
Keep in mind that Chrome Extensions and Packaged Apps are not drop-in UI frameworks for creating web apps. They are specific technologies for augmenting the browser experience and creating desktop-like apps, respectively.
For example, if you are creating Amazon.com you would not create the main website as an Extension or Packaged App. You would probably develop it using a typical web development stack and release it as a typical web site. Then, you might create a Chrome Extension that pops a window down in your Chrome browser and shows your recent orders, or that finds products on the Amazon store as you browse the internet, but you would probably not create the entire site as an extension.
With Packaged Apps you might create a desktop application that interacts with Amazon but this is really just a desktop application.
Yes of course this is possible but what you are making is a web application A chrome extension is literally a extension of chrome(which has to be installed) written in C or C++ (Just using javascript, html and css is possible). The handy thing about a web application is that it can be used (In every browser) without having to instal any extra components.
To be specific google has extensions and apps. With a specific chrome app you can do more than a regular web page. At first people would have to install the app and agree with the terms of use. this done you have more options in javascript which are normally forbidden for a casual webpage.
A extension is meant to add or change functionalities in chrome like adding your own video player extension to play avi or something like that. Not for building a web application.
If I where you just make a regular web application or create a chrome specific Packaged App.
In your case you are creating a private web application. If it is going to be used inside a lan you can just create a intranet and run your webapp there. If it has to be used global over the internet that you should just secure it with a login.
Or build a desktop application.

Using App Engine Python application as proxy to PHP application

During the past two years I have built an App Engine application in Python. Soon it will be possible to use PHP on App Engine. I would like to use off-the-shelf PHP applications such as Wordpress, Mediawiki and phpBB together with my Python application. To the user it should be transparent which of the two applications (Python or PHP) she is using for a particular page. I consider the Python application to be the main application where I will do most of the programming. This is because I have more experience with Python and also because I already have written a lot of reusable code for App Engine.
Currently my approach is to build a proxy in Python that maps HTTP requests like this:
http://www.yellow.com/blog/* to http://phpapp.appspot.com/wordpress/client1/*
http://www.yellow.com/community/* to http://phpapp.appspot.com/phpbb/client1/*
yellow.com is a domain mapped to my Python application.
http://www.blue.com/wiki/* to http://phpapp.appspot.com/mediawiki/client2/*
http://www.blue.com/* to http://phpapp.appspot.com/wordpress/client2/*
blue.com is a domain mapped to my Python application.
Besides the blog, community or wiki, there are a lot of URL's that don't require PHP. These URL's are handled by the Python application. For example: http://www.yellow.com/admin/*.
I'm still struggling with the proxy to get the passing of cookies between the two applications right, but I think it's possible to do this.
It would be awesome if I could get it to work this way. However, it seems to me this is not the most elegant way to handle this. I know I could use subdomains to serve the PHP applications, but I would rather just use URL patterns. Also, with the proxy approach, I can tweak the returned HTML by the PHP application before serving it to the user. Another advantage of this approach is the ability to cache the pages from the PHP applications in memcache.
I would like to hear what you think of my approach to use Google App Engine (custom) Python and (off-the-shelf) PHP applications together. Will I run into problems with the proxy (Javascript, cookies, ...)? Would it be better to build everything in Wordpress, for example, with custom plugins written in PHP (the plugins could fetch data from the Python application)? Other suggestions?
Your use case is a good example of what Appengine's Modules are intended for. Take also a look at the dispatch mechanism.

Connect appengine with cakephp

I'm thinking in create a webapplication with cakephp but consuming python's appengine webservice. But, to install cakephp etc, I need to configure the database. Appengine uses another kind of datastorage, with is different from mysql, etc.
I was thinking in store the data in appengine, and using the python webservices, and with the cakephp application comunicating with the webservice, for insert and retrieve data.
Is there any good resource for this, or is it unpossible.
Obs: also opened for a possibility for developing the webapplicaiton completely in python running in appengine. If anyone has a good resource.
Thanks.
I think that you should try different solution: http://aws.amazon.com/simpledb/
It appears that CakePHP is a MVC framework that's very similar to django, which is included in app engine for python. I'm not sure why you would want to store your data in google app engine, unless you're dealing with an extremely large amount of data, in which case you're likely comfortable enough working in python to just make the app work entirely on GAE.
See the official docs for more info:
http://code.google.com/appengine/docs/python/overview.html
http://code.google.com/appengine/articles/django.html
What you can do is run your CakePHP app on a standard LAMP web host and access the GAE Data Store through a REST or RPC web service. This isn't such a bad idea if you already have a CakePHP front-end that deals with RPCs in the backend, but if your Cake app stores all it's Models in MySQL it could take considerable effort to adapt it.CakePHP Models abstract their storage method using the DataSource class. You might be able to find a DataSource class that uses REST or RPC. However, if you don't have a very considerable investment in CakePHP Controllers and Templates I would suggest simply building your app entirely in GAE
You can not run PHP on GAE. If you run PHP somewhere, it is a bad architecture to go over the internet for your data. It will be slooooow and a nightmare to develop in.
You should store your data where you run your php, unless you must have a distributed, globally scaling architecture, which afaiu not the case.
There's a detailed tutorial on getting CakePHP up using the PHP runtime that Google recently announced. http://aymanrb.blogspot.com/2013/05/cakephp-deployment-on-google-app-engine.html

Is it possible to integrate user databases between Drupal and an ASP&SQL Server platform?

We have a game project designed on ASP&SQL Server, and we need to integrate it's user database with Drupal.
This would be easier from Project to Drupal (since there is user_save and user_delete functions available globally by using drupal bootstrap) but I'm not sure if we can execute PHP functions on an ASP platform.
Is there any documentation for this kind of problems? What do you suggest?
First of all, I think you should rethink your strategy. Why did you choose ASP & MSSQL and why did you choose Drupal?
But if you really want to stick with it I guess by far the easiest way would be to write a PHP (SOAP) webservice that can be used to interact with Drupal (ie. add/delete users) using the Drupal API, and call this from your ASP code.
****edit****
You could use the SOAP Server and Services modules of Drupal. Or just write a plain and simple webservice from scratch using the PHP soap classes.
If you're just looking to use the games user database for authentication I know Drupal has a few modules that allow for authentication via external services. I believe basic or digest HTTP is pretty straightforward but it probably wouldn't be too difficult to write a services layer on the ASP app. Check out Drupal's "user access/authentication" section for ideas on external authentication.
you can build your own drupal module and build an api that exposes everything you want to do, im pretty sure asp.net has a lib or something should be out there to build a simple xml-rpc, rest client, avoid soap, you will add an extra layer that you dont really need

Categories