Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
becki:linux:php [2010-12-14 08:20] becki |
becki:linux:php [2018-01-30 09:02] (aktuell) becki [Solution] |
||
---|---|---|---|
Zeile 79: | Zeile 79: | ||
=== Passing to and returning from Functions == | === Passing to and returning from Functions == | ||
+ | |||
<code php> | <code php> | ||
function f($v) { $v[0]= 1; } | function f($v) { $v[0]= 1; } | ||
Zeile 137: | Zeile 138: | ||
===== Logging == | ===== Logging == | ||
- | Use [[phpfn>function.error-log|error_log()]] for debug logging. | + | Use [[phpfn>function.error-log|error_log()]] for debug logging. |
- | ===== Command Line Usage == | + | If the calling PHP script is run by the web server, the output usually goes to ''/var/log/httpd/error_log'' whereas if if the script is called from the command line, the output goes to ''stderr'' (tested). |
- | + | ||
- | 2004-02-13 14:45 | + | |
+ | ===== Command Line Usage == | ||
==== Prerequisites == | ==== Prerequisites == | ||
Zeile 150: | Zeile 150: | ||
* Optin -qC is necessary in shebang; therefore use it BY DEFAULT! (-q suppresses header; -C keeps working dir) | * Optin -qC is necessary in shebang; therefore use it BY DEFAULT! (-q suppresses header; -C keeps working dir) | ||
* set register_argc_argv = On in /etc/apache/php.ini | * set register_argc_argv = On in /etc/apache/php.ini | ||
- | |||
==== Command Line Arguments == | ==== Command Line Arguments == | ||
Zeile 200: | Zeile 199: | ||
Note that STDERR seems only to be available when script is called from command line */ | Note that STDERR seems only to be available when script is called from command line */ | ||
fputs(STDERR, "Some msg!\n"); | fputs(STDERR, "Some msg!\n"); | ||
+ | </code> | ||
- | /* writing to System error log eg. /var/log/httpd/error_log | + | See also [[#logging]] |
- | Use it when the script is called from web server */ | + | |
- | error_log("Value $val"); | + | ===== 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> | </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 == |