Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
becki:linux:php [2011-01-05 13:54] becki |
becki:linux:php [2018-01-30 09:02] (aktuell) becki [Solution] |
||
---|---|---|---|
Zeile 202: | Zeile 202: | ||
See also [[#logging]] | See also [[#logging]] | ||
+ | |||
+ | ===== Handling own libraries == | ||
+ | ==== Requirements == | ||
+ | |||
+ | - We want to intstall the lib somewhere under ''/usr/local/...'' to separate it from files of the Linux distribution | ||
+ | - We don't want to interfere with the C libraries in ''/usr/local/lib/'' | ||
+ | - The lib shall be easy to inlcude without the need for an absolute pathname. | ||
+ | - We don't want to tweak the ''include_path'' in ''php.ini'' | ||
+ | - Older code which uses the lib must not break when the API of the lib changes | ||
+ | |||
+ | ==== Solution == | ||
+ | |||
+ | Example with a self-written PHP library called ''mystuff'': | ||
+ | |||
+ | * Install the lib in ''/usr/local/lib/php/mystuff0''. This fulfills 1 and 2 | ||
+ | * Make a symlink from a dir which is specified in the PHP ''include_path'' to the real lib, eg: ''/usr/lib/php/mystuff0 -> /usr/local/lib/php/mystuff0''. To find out what the ''include_path'' is, use ''phpinfo()''. This fulfills requirement #3 and #4 | ||
+ | |||
+ | <code php phpinfo.php> | ||
+ | <?php phpinfo(); ?> | ||
+ | </code> | ||
+ | |||
+ | The number appendix specifies the API version of the lib. When the API of the lib changes, then the version number must be increased. This is the case when exported functions are removed, when their behavior changes or when the signature of the function changes. Note that adding more functions (or classes) to the lib do not break the API. | ||
+ | |||
+ | With every new API you have to install a new lib and keep the older ones: | ||
+ | |||
+ | /usr/lib/php/mystuff0 -> /usr/local/lib/php/mystuff0 | ||
+ | /usr/lib/php/mystuff1 -> /usr/local/lib/php/mystuff1 | ||
+ | /usr/lib/php/mystuff2 -> /usr/local/lib/php/mystuff2 | ||
+ | |||
+ | It should be ovious that you should avoid to change the API too often! | ||
+ | |||
+ | |||
+ | Note that in C you need not to specify a version number. This is resolved by the linker which seems to automatically write a reference to the newest lib into the binary at compile time. | ||
===== Draft: Pages and Actions == | ===== Draft: Pages and Actions == |