PHP 扩展与库(以及是否可以转换)

发布于 2024-10-17 00:16:33 字数 228 浏览 7 评论 0原文

一些 php wamp/lamp 软件包附带了打包在 php_amf、php_db、php_gd2 之类的 php 扩展,我只需激活该扩展,或者如果默认情况下未安装该扩展,则安装该扩展。

我的一般问题是,这些扩展与库有何不同? 具体来说,我想知道,扩展可以变成项目本身加载的库吗?目标是调用该库,而无需像 php 扩展那样进行特殊安装。有时,当您使用共享主机时,您没有足够的权限来安装新扩展。

Some php wamp/lamp packages come with php extensions packaged within like php_amf, php_db, php_gd2 and I just have to activate the extension, or install the extension if it doesn't come by default.

My question in general is, how are these extensions different from libraries? and in specific I want to know, can an extension be turned into a library that's loaded in the project itself? the goal is to call the library without special installations like php extensions need. Sometimes when you're on shared hosting, you don't have enough privileges to install a new extension.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼趣 2024-10-24 00:16:33

PHP 扩展是围绕 Zend Engine 的 C 或 C++ 程序,它在 PHP 安装中提供 PHP 函数和类。

PHP 库是用本机 PHP 编码的程序,可能会或可能不会使用扩展在 PHP 程序中提供函数和类。

虽然将 PHP 库转换为扩展是可能且相当容易的(假设您有足够的 C++ 知识),但相反的过程可能是一个乏味的过程,因为 C++ 程序可能使用 PHP 中不可用的函数和对象。

将 PHP 库转换为扩展更容易,因为显然 PHP 函数都可以在 C 中使用,无论怎样,因为 PHP 是用 C 编写的。然而,相反的情况并不总是如此。

A PHP extension is a C or C++ program, wrapped around the Zend Engine, that provides PHP functions and classes within a PHP installation.

A PHP library is a program coded in native PHP that may or may not use extensions to provide functions and classes within a PHP program.

While it is possible and fairly easy (assuming you have enough C++ knowledge) to transform a PHP library to an extension, the opposite can be a tedious process, because the C++ program may use functions and objects that are not available in PHP.

It's easier to convert a PHP library to an extension, because obviously the PHP functions are all available in C, one way or another, since PHP is coded in C. The opposite is not always true however.

左秋 2024-10-24 00:16:33

PHP 扩展是用另一种语言(通常是 C 或 C++)编写的,它扩展了 PHP,使其能够完成 PHP 在实践中无法完成的事情。例如,与 PHP 内置函数尚不支持的操作系统或 Web 服务器的直接交互。扩展还允许从 PHP 中重用用其他语言编写的现有代码;尽管理论上可以用 PHP 重写该库,但这样做通常是不切实际的,并且重用代码可以用更少的努力提供更多功能,并且允许将来对代码的更新只需很少的努力或不需要努力即可合并。

PHP 库只是 PHP 代码的共享集合,因此虽然它允许多个开发人员重用代码,但它并不能让您执行任何您无法(理论上)自己编写 PHP 代码的操作。

就将扩展转换为库而言:这取决于扩展的用途。如果可以使用原始 PHP 完成,那么您可以对其进行转换,但这几乎是功能的完全重写。它还可能会使代码变慢。

A PHP extension is written in another language (usually C or C++) and extends PHP to allow it to do something that couldn't be done in practice with PHP. For example, direct interaction with the operating system or web server that isn't already supported by a PHP built-in function. Extensions also allow existing code written in other languages to be reused from PHP; even though the library could in theory be rewritten in PHP, it will quite often be impractical to do so, and reusing code gives more features with less effort and allows future updates to the code to be incorporated with little or no effort.

A PHP library is just a shared collection of PHP code, so although it allows code to be reused by more than one developer, it doesn't enable you to do anything that you couldn't (theoretically) write PHP code for yourself.

In terms of converting an extension to a library: It depends what the extension does. If it can be done with raw PHP, then you can convert it, but it's pretty much a full rewrite of the functionality. It may also make the code slower.

ぃ弥猫深巷。 2024-10-24 00:16:33

可以将扩展变成库

吗?不会自动。扩展不是用 PHP 编写的;因此不能简单地转换。当然可以编写执行等效操作的 PHP,但这样的脚本会比原始扩展慢得多,因为 PHP 的计算效率相对较低(与本机/编译语言相比)。

can an extension be turned into a library

Not automatically, no. An extension is not written in PHP; therefore it cannot be simply converted. It's of course possible to write PHP which performs the equivalent operations, but such a script would be significantly slower than the original extension because PHP is relatively inefficient for calculation (when compared with native/compiled languages).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文