How to install PHP pthreads extension on Ubuntu?

来源:互联网 发布:流体力学计算软件 编辑:程序博客网 时间:2024/05/17 20:08

http://stackoverflow.com/questions/15782860/how-to-install-php-pthreads-extension-on-ubuntu


up vote8 down vote favorite
2

I'd like to install the 'pthreads' PHP extension on Ubuntu. I'm using Ubuntu 12.04.1 LTS. And I can upgrade if needed. I really don't want to compile anything from source. For example recompile PHP from source sounds like a horrible idea to me.

In my view, the best option is to install this extension with aptitude command. For example likeaptitude install php5-mysql. Another good idea is to use pecl pecl install pthreads. But is does not work for me because of the following error:

checking checking for ZTS... configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled

Let me explain why I don't like the idea to recompile PHP from source:

  • I guess I should uninstall original PHP package then and all the dependencies. Because if I compile it over standard PHP then any packages update would overwrite my changes. And yes, another option is to keep PHP from updating. Anyway this introduces some extra work and makes the setup more complicated. We work in the distributed team. And I don't want other people to deal with this complicated setup on production servers.
  • I want to install updates on servers. And I don't want to recompile PHP because of security fixes etc.
  • I don't want to compile anything on production servers and do this many times. Then I should build my own packages and update them with new versions etc. Sorry but I'm not smart enough to do this. May be in 2-3 years but not now. Because there are a lot of things to keep in mind here. For example how, to replace standard PHP package with custom package while still satisfying all dependencies.

2   

I guess you'll have to compile it. All the resources I found online say that you have to. Btw, it is not that hard. – Bart Friederichs Apr 3 '13 at 9:00
 
Got to agree with @BartFriederichs, if you somehow manage to do it , please tell it how. – confiqApr 3 '13 at 9:19
 
@BartFriederichs, thank you for the comment. I agree that this is not really hard. The thing is how to install it on several production servers. Perfectly I should create my own package, put it in my own distribution and install it on the servers with aptitude from my distribution. But I don't do this for MySQL driver because this is already done. And I want to believe I'm not the only person using pthreads and the same setup should be done for pthreads too. – Victor SmirnovApr 3 '13 at 9:20
 
@confiq, thank you. I don't loose my hope. – Victor Smirnov Apr 3 '13 at 9:22
 
If yo have several servers, you can just copy the.so file. Or choose a distro that packages it for you (don't know if they exist). – Bart FriederichsApr 3 '13 at 9:33

2 Answers

activeoldest votes
up vote9 down vote accepted

ZTS: [Z]end [T]hread [S]afety.

ZTS is a compile time option that cannot be enabled at runtime. It allows the PHP interpreter, which usually executes in a single thread, to be executed in many, each with their own isolated instance of the interpreter.

The only option for you appears to be a fresh build, and then using package building tools for your distribution.

I'm not able to advise on the creation of a deb directly, however, creating an rpm is quite trivial,https://github.com/krakjoe/spex there's a starting place for that, you can then use alien to turn an RPM into a deb if you are not able to find out how to create deb packages directly.

Building from source is going to be inescapable, unless you can find some repository with a thread safe build of PHP, with a complete build environment. To that end, the informationhttp://pthreads.org/building may be of use to you. It really isn't that hard to build PHP, nor does it take many hours, on modern hardware you can have a build in less than a minute. You can and should take the opportunity to trim the fat from your installation.

On a side note, the article you reference about PHP not being thread safe is from 2008, it's very wrong. The core is thread safe, there are a few extensions that are inherently unsafe ( not abstracted badly, but fundamentally unsuitable ).

shareimprove this answer
 
 
Thank you for the comment, it is really helpful. It makes me believe that I'm moving on the right direction ;) – Victor Smirnov Apr 3 '13 at 18:06
3 
Broken Link .. Please fix ... – BabaMay 19 '13 at 17:33
 
What's the difference between ZTS and the thread safe binaries that you can download off something like here:windows.php.net/download – CMCDragonkaiFeb 21 '14 at 9:40
 
Hi @Joe, the 'building' link is still broken. I'd edit your post directly, but can't find the link that was intended. – halferSep 28 '14 at 22:54
 
Debian and Ubuntu can install.rpm packages using dpkg -i packages.rpm. – DanFromGermanyFeb 9 '15 at 21:12
up vote6 down vote

It seems, Ubuntu doesn't have a package for the thread-safe PHP in the official repositories.Pthreads extension requires ZTS. Thus, you have two options:

  1. compile it yourself:
  2. find a .deb package somewhere, e.g. repositories of the other Debian-like systems.

I'd compile and package it myself using "checkintsall" utility. Thus, Apt will have ability to keep track of PHP version. I would also request Canonical for a package for ZTS PHP.

shareimprove this answer
 
 
Thank you for your answer. I think many people should do this when installing pthreads on Ubuntu. This is why I thought that there should be some solution. But this turned out to be rather complicated question. And I guess Canonical does not include thread-safe PHP binaries intentionally. But may be there is some project where this is already done? – Victor Smirnov Apr 3 '13 at 13:07
 
Good note on checkinstall. This will help to keep maintainable packet cache. With checkinstall it is also possible to set up a corresponding version, since there can be problems adding the deb to the installed packages. Best check with apt-cache show <collision-packages-during-install> to get the required version or just pack it (checkinstall) with your systems versionapt-cache show php5 | grep Version. – Sebastian LangeOct 31 '14 at 11:48

0 0