Using Ruby library in PHP application - php

I am working on a PHP project that makes use of MLB's Gameday data. There appears to be a pretty solid Ruby library for working with data. I don't particularly want to rewrite the entire library in PHP, so I was wondering if anyone had any suggestions for a good way to interact with the Ruby scripts from my PHP application.
I'm starting to think that I'll need to write some sort of command line Ruby script that'll interact with the Ruby classes and output the data in a format usable by PHP (JSON, XML).
Are there any better ways to do accomplish this?

Another option is to use Gearman, written by the the same team that brought us memcached. It has PHP and Ruby bindings.
You'd create a daemon in Ruby that exposes functions to Gearman, then have your PHP code call those functions through Gearman. No Apache needed.
(Boy, I'm on a Gearman plugging streak. I wish I was getting paid for it!)

Rather then a command line interface, I'd suggest outputting data in JSON format and requesting that data via PHP & CURL.
If you needed to you could even write a REST interface for it pretty easily.

Related

CIM/SMI-S Client with PHP

I'm working on a web interface to pull information from storage arrays. I'd like to use SMI-S There are Java CIM clients I can use (SBLIM CIM Client), but I'd really like there to be a way for PHP to pull information via CIM. Can anybody point me in the right direction? Is there a way I can, say, send a request over http (port 5988) and just parse out an xml response?
If anybody can suggest a better way that'd be great as well. Thank you.
I don't know of a CIM client written directly in PHP, but normally you can integrate packages written in Perl or Python into your server side PHP.
You could also integrate a command line CIM client into PHP, e.g. cimcli from OpenPegasus, but parsing the output of a command line client may not really be convenient.
I would recommend against writing your own CIM-XML parser - there are many details to observe in the specs (DSP0200, DSP0201), this would definitely be a major undertaking.
For Python, there is the PyWBEM CIM client which works very well, even though there is not much activity on the project. Also, there is the PowerCIM CIM client for Python, which is newer but I did not use it yet. PowerCIM provides the CIM classes as Python classes, while PyWBEM provides generic Python classes such as CIMInstance or CIMClass. Just two different styles to deal with, for integration into a next higher layer such as PHP it seems to me you'd be better off with the generic style provided by PyWBEM.
There is a Perl interface on top of the OpenWEM client, but I don't have experience with that.
Andy
SMI-S calls to get array details may use GetInstances() or EnumerateInstances(), which are basically predefined methods. These methods come with library such as OpenPegasus. If you are successful in including the required libraries, then you can create the client variable, connect to the CIM server and invoke the required method.
If you are specifically using OpenPegasus, you may need to know how to use C++ in PHP as the former is implemented in C++. Refer http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/

How would I go about expanding my PHP code library with Python code?

I have a rather large API written in PHP that I've worked on for years. Some of the functionality needs to be upgraded to the extent where I should really just rewrite the classes. Since I need to scrap the old code anyway, I was thinking perhaps I could replace the old functionality with Python code.
I came across PiP while searching for answers, and it seems like an exellent solution (Since I can actually create Python class instances in PHP and call their methods etc.) but it seems it was abandoned in the Alpha stages for reasons unknown to me.
I suppose the simplest solution would be a CLI one, meaning I could run a python instance from PHP and collect the results. I don't particularly like this solution though, considering the amount of Python code I'd have to write just to handle input from PHP and respond accordingly. Plus it's not very reusable.
I don't know if this is a normal problem, Google certainly don't seem to think so, but what would be the best way of complementing a PHP code library with Python code?
I can think of two options, which should also make the overall solution somewhat more flexible:
Write it as a web service: Write the python parts as a RESTful web service. Should be relatively straightforward to do.
Use something like ZeroMQ to create a message queue: There are zmq libraries for both PHP and Python, which should also make this option not very difficult to implement.
As you may have noticed, all the options can be somewhat clunky in nature. You didn't mention what exactly did you mean by "API" (eg. is it a library or web service or what), so depending on what it is, it might just be easiest to rewrite it in PHP - it's not a bad language in the end if used properly.
After some time researching this, I've concluded that there is no worthwhile way of building on a PHP library with Python code. The PiP project was the closest thing I could find but it has been abandoned.
My solution has been to declare a 2.0. Every new function I add I write in Python. I translate some code from PHP to Python when necessary. It's working great so far!

Can node.js be integrated with php?

is that even a good idea for scaling heavy php apps ? for example, how does node's mysql module compare to php's mysqli extension in terms of performance etc ..
I'd seriously consider wrapping your PHP app with node.js; that is, having a migration path of your existing PHP being called by your node code, eventually migrating the PHP code into Javascript. The reason being, the execution model of node.js (non-blocking) doesn't really play well with PHP's execution model. That said, the execution models can be made more compatible with a wrapping approach; that is, having node be your exposed server, and making appropriate PHP calls (re-request); you can likely use that process to "migrate" your "wrapped" PHP over to a node server, then slowly migrate your PHP code to node.
Of course, this begs the question of whether or not you really even need / want to do this, but that's for you to determine...
There are some pretty good mysql libraries available in node.js with okay performance, but I would just rewrite(because you will still have to do a lot of coding when you use mysql libraries) the slow parts in node.js using redis or mongodb and just keep the rest in PHP. Especially redis with node_redis(hiredis) is very fast. You can use NGinx to do the proxing.
Output the result or data fetch from mysql via Nodejs is better than via LAMP.

Local video tanscoding platform

I was search for a video platform which I can use as a web-service and install locally on my local server to my PHP website.
I know we can run PHP shell commands but I need to implement a solid system with the Transcoder.
So, it should provide a API using REST or SOAP to convert videos, convert videos in efficient way. Create video thumbnails. If it a ruby or Python then it would be great and should be a free and open source one.
I could see those Software on Github, seems its good but having limitations. https://github.com/streamio/streamio-ffmpeg.
Is this a bad idea to use Perl or Python written application using with PHP? what are the available FOS software
Is this a bad idea to use Perl or Python written application using with PHP?
A bad idea? No. But it can be annoying sometimes.
If you really want to use a web service for this instead of just calling exec/proc_open like the rest of the world, you can go ahead and do that without too much concern.
Another option available to you is Gearman a distributed work queue/RPC service with bindings for many languages, including PHP, Python and Ruby. You can easily write a daemon in Ruby that uses that ffmpeg wrapper, and call methods directly from your PHP code. Thanks to how Gearman works, you can easily scale out the video encoding services by just adding more workers.
You can use FFMPEG binary for conversion/thumb extraction with command line like exec() in PHP

Flex with PHP

I'm new to Flex and done a few application with only client side programming. Now I'm trying to do the back-end stuff using PHP. Can some one explain where(which folder) to put the PHP file for the Flex file to communicate with PHP. I'm using Flexbuilder 3 IDE.
Thanks
Flex will not access your PHP script via the filesystem, you have to invoke your PHP script via a web server. The easiest solution is to use XML as in your data transport language. But you can get fancy and use something like BlazeDS
This all really depends on what you want. I would make a very different recommendation if you wanted to simply poll the server occasionally than if you wanted to have a regular interface between the two.
If you are simply polling the server, I would recommend simply using the HTTPRequest class. It will allow you to create POST and GET data and serve to communicate relatively well.
On the other hand, if you are looking to have a more complicated set of communications between the server and the SWF, your best bet is the RemoteObject class with either AMFPHP, WebOrb, or an equivalent (we use WebOrb where I work). This has the benefit of allowing you to have objects of similar name/type in both Flex and PHP, meaning that communication can be made a good deal more comprehensive.
(If you are working this way, email me cwATallen-poole.com and I can give some pointers so that you do not have insane compiler arguments for Flex).
The next option is to use the XMLSocket class, but that seems to be a bit more intense than what you are looking for.
You may want to take a look at AMFPHP too, pretty handy.
Try XAMPP.Very useful.
The new Flash Builder 4 (product formerly known as FlexBuilder) supports connecting to PHP services out of the box. The use the Zend Framework to do it, and will install the framework to your test webserver for you whenever you go to setup a data service.
Adobe video tutorials:
Part 1
Part 2
Another good, non-video tutorial

Categories