PHP – DanDev.com http://www.dandev.com Tidbits about software development Sat, 26 Oct 2013 00:22:44 +0000 en-US hourly 1 Compiling php-python on Fedora Linux http://www.dandev.com/2012/11/compiling-php-python-on-fedora-linux/ http://www.dandev.com/2012/11/compiling-php-python-on-fedora-linux/#respond Tue, 13 Nov 2012 04:25:17 +0000 http://www.dandev.com/?p=354 So, I haven’t posted in a while, and I felt it was about time to get some fresh content up here so what follows is the result of some research […]

The post Compiling php-python on Fedora Linux appeared first on DanDev.com.

]]>
So, I haven’t posted in a while, and I felt it was about time to get some fresh content up here so what follows is the result of some research and testing I did as a result of re-visiting a question on SuperUser that I responded to over a year ago that was never fully resolved.

So, you want to run python code in PHP, eh? Why you might ask? Well, I’m not quite sure. I haven’t run in to a use case for it myself, but I can see where you might need to do some heavy-duty maths or maybe there is a python library that you require for some custom algorithm or something.

Good news! There is a PECL library you can use for this task: http://pecl.php.net/package/python
Unfortunately, it hasn’t been updated in over 4 years at the time of this writing and was in alpha at the time of the last release.
However! The maintainer appears to still be working on the package, but over a GitHub: https://github.com/jparise/php-python
Unfortunately, it still doesn’t compile on PHP 5.4 (in Fedora at least)
However! I got it to work with some minor tweaks.

Here is the process that works with the current PHP version (5.4.8 at the time of this writing) linking to python 2.7:

Install build tools and minimum deps:

yum groupinstall "Development Tools"
yum install php-common php-pear php-devel python python-devel wget

Get a copy of the latest version of php-python:

git clone https://github.com/jparise/php-python.git php-python

Apply the patch to fix C syntax errors. Note that this patch is likely to be broken and/or not necessary some time in the future when php-python is updated. But the changes are simple so you can apply them manually if they are still needed in future versions. Gist also available here: https://gist.github.com/drener/7149541

wget http://www.dandev.com/other/post_content/php-python_20121112.diff
patch -p0 < php-python_20121112.diff

Build the module

cd php-python
phpize
./configure
make
make install

After this is complete you need to edit your php.ini to enable the new module. Add a line like this:

extension=python.so

Once php.ini is updated you should be able to see the "python" module listed in the "php -m" modules list, and you should be able to use the python functions. Restart Apache if you are using mod_php to load the updated php.ini file. The examples folder on GitHub has some code you can use to see the Python features in action: https://github.com/jparise/php-python/tree/master/examples

Good luck!

The post Compiling php-python on Fedora Linux appeared first on DanDev.com.

]]>
http://www.dandev.com/2012/11/compiling-php-python-on-fedora-linux/feed/ 0
Fatal error: Cannot redeclare pclziputilpathreduction() http://www.dandev.com/2009/01/cannon-redeclare-pclziputilpathreduction/ http://www.dandev.com/2009/01/cannon-redeclare-pclziputilpathreduction/#comments Sun, 25 Jan 2009 14:39:23 +0000 http://www.dandev.com/?p=104 I’ve seen this in a couple of places already, so I’ll go ahead an post it: If you’re getting an error with your WordPress install similar to: “Fatal error: Cannot […]

The post Fatal error: Cannot redeclare pclziputilpathreduction() appeared first on DanDev.com.

]]>
I’ve seen this in a couple of places already, so I’ll go ahead an post it: If you’re getting an error with your WordPress install similar to: “Fatal error: Cannot redeclare pclziputilpathreduction()” and you’re using WP 2.7+, disable your WPAU – WordPress Automatic Upgrade plugin. This error is caused because in version 2.7 WordPress added the ability to update itself, so this plugin is no longer needed. Here is an image of what the deactivated plugin should look like on the plugins page:
wpau-deactivated

Update: This appears to be fixed in the latest version of the plugin. I was able to enable the plugin and browse around without getting errors. But I don’t see the need for this plugin in WP installs newer than 2.6 anyway.

The post Fatal error: Cannot redeclare pclziputilpathreduction() appeared first on DanDev.com.

]]>
http://www.dandev.com/2009/01/cannon-redeclare-pclziputilpathreduction/feed/ 6
PHP 5.3alpha http://www.dandev.com/2008/09/php-53alpha/ http://www.dandev.com/2008/09/php-53alpha/#respond Mon, 22 Sep 2008 01:56:02 +0000 http://www.dandev.com/?p=70 The next minor version of PHP5(5.3; currently in the alpha stage) will include support for NOWDOC, Lambda functions & Closures, and the much anticipated ternary shortcut(?:). NOWDOCs are basically HEREDOCs, […]

The post PHP 5.3alpha appeared first on DanDev.com.

]]>
The next minor version of PHP5(5.3; currently in the alpha stage) will include support for NOWDOC, Lambda functions & Closures, and the much anticipated ternary shortcut(?:). NOWDOCs are basically HEREDOCs, but without interpolation. It’s like using single-quotes versus double-quotes in your strings. Lambda functions allow you to define a single-use function so that it doesn’t have to be defined in the global scope of the script throughout execution. You can exectute things like loops or callbacks without having to define the function ahead of time, and you can return the value of your loops or callbacks to a variable directly. The Ternary shortcut is to allow you to perform a quick if() & return the result, which is what the Ternary operator(s) does already, but you don’t have to specify an “else” value. Most(all?) of these features were discussed for inclusion in PHP6, but it looks like they’ve been backported, which is good. 🙂

Also included will be “limited GOTO” which, as I understand it, will entail using the break language construct to jump to a certain position in the script. The information that I’ve seen is minimal, but this feature could be useful to a lot of people as well.

The post PHP 5.3alpha appeared first on DanDev.com.

]]>
http://www.dandev.com/2008/09/php-53alpha/feed/ 0