I need to make my PHP app cooperate with CPLEX Solver. The good news is I'm familiar with LP, but the bad news is I haven't used CPLEX until now. From the documentation I can see that using CPLEX is fairly easy through the integrated IDE, or via default C, JAVA, C#, Python APIs or a callable library API. Unfortunately, I can't seem to find any examples at all of CPLEX being used from PHP.
Is such a thing even possible? I know I can execute any bash command through exec, but CPLEX often requires several interactive steps to be performed to solve a single problem, and I don'g know how to do that from PHP;
If answer to 1. is 'yes', can anyone share even a simple example of how it can be done? I.e. a PHP script that calls CPLEX to resolve an LP problem.
There won't likely be any ready made examples because there is only a callable lib for C and an API for C++, Java and C#. There is also a separate Python API.
You could potentially use Gearman or write a REST wrapper in Python that your PHP app could consume.
Alternatively you could write your own PHP extension that wraps the C functions you need to call. Not sure if you can precisely what you need to do with Zephir but you could have a look - it's really simple to get started with...
Related
There's a PHP library that I'm really interested in using. However, there's no R implementation of it nor do I see an interpreter between the two. I've searched on Google but it seems like most implementations are either displaying R plots or figures on a webpage via PHP or passing command-line arguments to each script. R blogger article about PHP and R seemed to be geared towards building a web application.
I've seen reticulate package achieve similar this within Python, but I was hoping we have something like this for PHP.
I've thought of a method of passing it through via exec(paste0('php ', <script>), but I don't think that's the best direction to take.
Are there better ways to implement this?
When I look through the source code files I have downloaded from the PHP website, I get lost so easy. What I would like to do is obtain all the source code needed to create a Console application that takes your PHP code and executes it. I would also like to maybe be able to add C++ functions and calll them from PHP. I have done this quite simply with Lua on my Mac via Xcode, but I don't think it will be that easy using PHP on a different system using a different program.
You can write PHP extensions using C (or C++, I suppose) to expose libraries to PHP, but PHP isn't designed to be embedded in applications other than web servers.
Little 2019 update about #duskwuff comment.
PHP8 will have JIT compiler, so, no, PHP will no longer be used only for web.
As you can see on image, PHP8 compiler is faster than Java, C compiler etc.
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!
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é
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. ;)