Toolserver:PHP

This page was moved from the Toolserver wiki.
Toolserver has been replaced by Toolforge. As such, the instructions here may no longer work, but may still be of historical interest.
Please help by updating examples, links, template links, etc. If a page is still relevant, move it to a normal title and leave a redirect.

Getting started

Background scripts & scheduling

edit

PHP scripts can be left running on the server using a screen session or scheduled to run at set times using cron. PHP scripts run this way cannot use $_POST or $_GET variables.

Debugging

edit

Errors on page

edit

You can configure PHP to output descriptive error messages by adding these lines to the top of the PHP file:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Syntax errors

edit

If the page fails to load (error 500), you can check for syntax errors from the command line:

$ php -l myscript.php

On the toolserver, this will append errors to the user log. You can tail the file to see your syntax errors:

$ tail -f /var/log/userlog | grep myscript.php

Segmentation fault

edit

To debug a PHP script which crashes with a segmentation fault, type:

$ gdb php-cgi
$ run myscript.php

Then wait for your script to run. When it crashes, type:

$ bt

flush() does not work!

edit

flush() does not work. To be precise: flush() does work but a layer of buffering outside the PHP interpreter makes it appear to not work. Circumvention: send a lot of whitespace characters after the output that you want flushed - a total length of useful_text + whitespace greater than 8192 bytes should be sufficient. (Clearly, sending whitespace is a waste of bandwidth so this trick should be used sparingly.)

edit

Category:Programming languages