I really want to mix Lua and PHP, for example receive a PHP query and process some parts of the query using Lua scripts (being called from the PHP script that got the initial query ).
Any clues about this ? I've seen some libraries to use Lua as some kind of PHP replacement, but I've seen nothing clear about how to use both Lua and PHP together.
Thanks
Have you seen phplua? It looks like it could do what you want. I found it via the Lua binding-with-other-languages page (it was the only relevant option, for better or worse).
There is now a full PECL extension for embedding and interacting with Lua code.
See http://pecl.php.net/package/lua and http://www.php.net/manual/en/book.lua.php
I assume you aren't feeling up to embedding lua in PHP which leaves running lua as an external script and reading the result. That's a pretty common operation and this page provides some guidance.
Related
This might seem to be a silly question but I was wondering if there any programs out there that would scan over a directory of PHP scripts and generate a report that states exactly what databases and tables are queried in each particular script?
Our database type is MySQL. Thanks for your help.
You might try something like PHP Code Sniffer. It's a static analysis tool that can search through PHP code for certain rules. You may have to end up writing your own sniffing rules, but it might be somewhere you could start. I've used it to check PHP version updates and it's worked pretty well. Just search for 'php code sniffer custom standards' and you can find some useful stuff to help get started.
I have a script running in Ruby, and another in PHP, and, for my needs it's not possible to make it all run in the same scripting language.
I want to use PHP to create a variable in Ruby. Currently, I have this code:
PHP:
$config = fopen("config.txt","w+");
fwrite($config,$sArguments);
fclose($config);
Ruby:
while true do
file = File.new("config.txt", "r")
config = file.gets
file.close
end
The PHP will write the next configuration in a file and Ruby will read it and turn it into a variable. It works, but Ruby has to work on reading and reading the file, and it sometimes fail to read it correct, so this code is very badly optimized.
Is there a faster way to pass information from a PHP script to a Ruby script?
I'm no expert in PHP but I think "How to run Ruby code from Python (Python-Ruby bridge)" provides some ways of how to accomplish communication between the two languages. Although the page speaks of Ruby-Python communication, I'm pretty sure some of the suggestions can be implemented for Ruby and PHP.
One solution is to use XML-RPC to transfer simple data types from PHP to Ruby. Ruby has native support for XML-RPC and I think there are libraries for PHP to enable support for XML-RPC.
You can also use pipes. That is, you call your PHP script via Ruby's IO.popen. I've done something similar for Ruby-Python in "Feasibility of using pipe for ruby-python communication" but I have not really evaluated the performance.
It's difficult to say what the problem is exactly from the information given, but when you say Ruby sometimes fails to read I'm guessing it's your Ruby script reading the file when PHP is half-way through writing it.
An easy fix would be for PHP to write it to a temporary file and then move or rename the temporary file so it can be picked up by the Ruby script. Move/rename is atomic so there is no chance of a half written file being read.
A couple of improvements you could also make:
Use something like the listen gem to only read the file on an update.
I'm not sure what data you're passing, but you could use something like YAML as an interchange format. Catch any parsing exceptions and log the received data to aid debugging.
Taking a step back, if you're on a "real O/S", a simpler option would be to use message-based IPC via Unix sockets, assuming persistence is not a concern. Have a look at this page on "Introduction to IPC in Ruby" for a good intro with examples on passing messages between processes.
How can I access my php script from a Python script?
I need my Python script to be able to access the variables within the php script. (By the way, I'm new to php and Python.)
Thanks in advance.
If I understand it correctly, you have a service in PHP, and want to communicate with another one in Python.
Now, this is not really related to PHP or Python: this is quite a classic issue of integration and there are several ways to accomplish it; without more details about your problem, it may be very difficult to be specific about a solution and what kind of approach could be the better for you, but below you can find some ideas.
You could for instance save the status from PHP service in an ad-hoc table in the database, and then query it from the Python service.
Another way could be to use a RESTful approach: the information is available as a resource, accessible via a GET query; in PHP you would have a small handler that would just return a small JSON (or XML, if you like that kind of stuff), and in Python you would have instead the client. Of course, there are security issues to consider, but I think you got the idea.
For more information, I recommend you having a look at an interesting series written some time ago by Paul Stovell about integration. It is very accessible, and shows several approaches - although not all of them apply to your current issue.
Elaborate. Is the PHP file local? On a webserver? Where's the python file?
If the php file is on a server with the python file, use an exec statement.
If the python file is local and the php file is on a server, then you need to use urllib.
If both are local, write an interpreter...
I have this nice big Dev Kit written in PHP, but the application I'm currently developing is in CFML.
In an attempt to avoid rewriting the PHP, I'm going to try to just wrap the PHP in CF <script> tags and call the PHP functions when I need them.
Does anyone have any idea how to call one of those PHP functions inline in CF?
There's no built-in way to do this, but using CFGroovy (which allows you to inline any Java Scripting API-compliant language implementation) and Quercus (a PHP implementation in Java), you may be able to pull off what you want/
CFGroovy: http://www.barneyb.com/barneyblog/projects/cfgroovy2/
Quercus: http://www.caucho.com/resin-3.0/quercus/
A simple example including source code:
http://www.barneyb.com/cfgroovy2/
You can't. It's a whole other app engine. You could use CFHTTP to call a PHP page - but it's a bit overkill. You can look at Sean's solution here:
http://corfield.org/entry/ColdFusion_8_running_PHP
Edward M. Smith is right. You may be able to mix PHP and CFML by using Resin as your JVM. While I have not done so, I do believe it is possible to have Resin interpret your PHP code from within the same context as a CFML (ColdFusion) Web site.
A .cfm/.cfc could not contain any PHP and a .php file could not contain any CFML/CFScript;
however, those files could live side by side within your www.something.com domain.
Resin http://www.caucho.com/ is a Web Server/PHP Interpreter that is very fast and written in Java. It is the bundled JVM for the open source CFML project Railo.
Hope this helps.
You can pass data back and forth by having php/coldfusion store/retrieve client array's or variables.
One other choice is to force coldfusion to parse through .php files, for any coldfusion inside there. How it would handle the mixture of coldfusion and php, I am not sure...
I have a VPS Linux webserver with PHP installed.
I want to code some search engine or data mining stuff in one application which I am thinking of building in python.
I want to know if it is possible to use python and php together like calling functions of python in php and vice versa.
As it is my VPS server, I can install anything on that.
Has anyone tried using python in php? Are there any performance issues in real time??
You can execute python scripts using the exec() function in your php script.
Also this seems to provide an answer or two to your question.
Calling Python in PHP
You could have a look at PiP
To that end, I've [site author] written a Python extension for PHP. In short, this extensions allows the Python interpretter to be embedded inside of PHP (think of PHP as the parent language with Python as its child). This allows native Python objects to be instantiated and manipulated from within PHP. There is also initial support for accessing PHP functions and data from within the embedded Python environment.
However, I cannot comment on its reliability. Might need to test it for yourself.
You're trying to do something like
def helloWorld():
print 'Hello, World'
<?php helloWorld(); ?>
I'd say that you most certainly can't.
Edit: Have a look at php's shell_exec though.
I think that should be
<?php
$try = exec("/var/htdocs/folder/test.py")
?>
Try and see if it works
Better you have to do, use api, different application like one application on python server having python application and one server having php application with api. Like you store or delete data by using api in android or ios.