Jpgraph installation and configuration tutorial

Source: Internet
Author: User
Tags php error reporting
After learning the previous two phpjpgraph installation tutorials, as long as the jpgraph class library passes the PHP installation environment verification, you can officially install the jpgraph class library. In fact, jpgraph class library installation is very convenient, you only need to extract the downloaded jpgraph class library to the relevant directory in the established PHP environment. The key to jpgraph installation is the PHP configuration file. after learning the previous two php jpgraph installation tutorials, ini and jpg can officially install the jpgraph class library after the jpgraph class library passes the PHP installation environment verification, in fact, it is very convenient to install the jpgraph class library. you only need to extract the downloaded jpgraph class library to the relevant directory in the established PHP environment. The key to jpgraph installation is the PHP configuration file php. ini and jpgraph configuration file jpg-config.inc.php configuration. The following describes the jpgraph class library in English. I hope it will help PHP developers who use the jpgraph class library.

  Jpgraph Library installation

After verifying the installation conditions of the jpgraph class library, you can install the jpgraph class library. The so-called installation is to decompress the file and copy it to a directory structure that can be found in your PHP program. in Unix systems, the common installation directory is/Usr/share/php/There is no standard installation directory in Windows. you need to decide the directory you set when installing and configuring the PHP environment.

It is very important to find the jpgraph class library when you use the PHP statement require_once or include. It is recommended that the jpgraph installation directory structure beJpgraph/.

Suppose you have downloaded the tmp Directory of the Unix system of the jpgraph class library, the installation command on the Unix server is as follows:

1
2
3
4
5
Root:/tmp> tar xzf jpgraph-2.5.tar.gz

Root:/tmp> cp-r jpgraph-2.5/usr/shar/php/

Root:/tmp> ln-s/usr/shar/php/jpgraph-2.5/usr/shar/php/jpgraph

The last Unix command creates a connection for the directory location of the actual jpgraph version class library. When we need to use the jpgraph class library in different directories, we do not need to put a jpgraph class library in each directory. we only need to store the jpgraph class library in a fixed directory, then you can use the ln command link in other directories, without occupying disk space repeatedly.

  Instructions for configuring the jpgraph class library on the PHP development server

  Configure the php. ini configuration file

  Configure PHP memory

In most default PHP environments, there is not enough memory for the jpgraph program. because it requires a lot of memory, at least 32 MB of memory is required during configuration. Open the php. ini configuration file and go

1
Memory_limit = xx

Xx is a specific number. change it to 32 MB, that is

1
Memory_limit = 32 M

  Memory usage of jpgraph class library: When you need to create a very large image, the memory may not be enough. for example, suppose you need to create an image of 1200*1024 size. This means that it only needs 1200*1024*4 bytes, that is, 4.7 mb ram. when the php jpgraph class library is internally processed, it needs about three times the memory, that is to say, at least 15 mb ram is required. If you need to load PHP and the entire jpgraph class library in the memory and perform and parse them dynamically, it means that at least 15 mb ram is required. If the image is very complex and you need to create more objects (a typical example is a big Gantt chart), you need to double the memory, that is, 64 mb ram. (In fact, I personally think this section shows you how to calculate the approximate memory size based on the size of the image to be processed when using the jpgraph class library ).

  Configure the maximum PHP execution time

The maximum execution time of PHP configured by default is very short. It usually takes about 10 seconds. It is sufficient for general interactions or plain text processing. However, processing large and complex images takes more time. For this reason, the maximum PHP execution time must be increased to at least 20 seconds. (It takes 30-40 seconds to process your image complexity and related data)

Correspondingly, you need to modify the max_execution_time option in the php. ini configuration file.

1
Max_execution_time = xx

Change

1
Max_execution_time = 30

  Disable Cache output

Open the php. ini configuration file, find the output_buffering option, and change the option

1
; Output_buffering = xx

That is, comment out the cache output.

The reason for disabling the cache output is that during PHP development, we need to be able to see the potential error information of the jpgraph class library. enabling the cache will prevent the error information from appearing in time. To understand these requirements, you need to know the basic principles of the HTTP protocol. In particular, how MIME-encoded data works.

The following briefly describes the HTTP protocol:

1. when you enter a URI address in the browser, the browser requests data from the server through the GET or POST command.

2. the server replies to a data stream (or an error message is returned when the data is unavailable ). The prefix MIME information in the data stream tells the browser how to parse the data. The most common type is text/html. The browser is notified to parse data by embedding HTML-encoded plain text.

When the data must be parsed as an image, the MIME information prefix of the data stream is image/png or image/jpeg. When the browser receives MIME information, it parses the following image data in the indicated image encoding format.

Note that each server can only reply to one MIME type. This is the key to further understanding how to generate dynamic images. This explains why the header information sent by the server running the PHP program first shows that the data needs to be interpreted as images rather than sending images and text at the same time.

Now let's explain why the output buffer makes debugging of the jpgraph class library more difficult.

Generally, all PHP program outputs are ordered. for example, you must first send the header information and then send the data. If no header information is output or the text without the header information is output, the browser will parse it into text/html format. One purpose of caching is to allow data to be stored for a period of time. when determining the type of header information to be sent, the data is output after the header information is sent.

Enabling the cache may send the following information:

1. The program starts execution and the image is generated.

2. at this time, your PHP program may have some minor problems. These error messages are not directly output to the browser. Instead, they are allowed to be stored in the cache. When the program starts to output the image header information and image data, it will add the data to the cache where the previous error information is stored.

3. when the browser needs to parse the following data into an image because the image data is mixed with the previous error information, parse the data and the Red Cross (FireFox) will fail ).

When the cache is disabled, the error message will be output to the browser in time when debugging the jpgraph program, so that you can process it in time.

  Enable proper error check

In this section, you need to adjust the PHP error report level. The jpgraph class library can run securely even if all PHP error reporting levels are enabled.

The error level is set to the highest, that is

1
Error_reporting = E_ALL | E_STRICT

Note: in addition to the error level, it is best to configure the following options.

1
2
3
4
5
6
7
8
9
10
11
12
13
Zend. zemo-compatibility_mode = Off
Zend Engine compatibility may cause problems when using the jpgraph class library

Implicit_flush = On
This option reduces performance and should not be used on the product server. However, enabling this option will output all the output to the browser as soon as possible for compilation and debugging.

Allow_call_time_pass_reference = Off

Display_errors = On
Confirm to display all error messages

Display_startup_errors = On
Make sure that any initialization errors thrown by PHP can be reported in a timely manner.

  Set default time zone

If the default time zone is not set since PHP5.2, an error occurs when you use the jpgraph class library. You only need to open the php. ini configuration file and findDate. timezone =Change to Asia/Shanghai.

  Configure jpg-config.inc.php

In addition to the installation and font support in the standard jpgraph configuration, only one important jpgraph configuration is specifically for the development server, that is, the localization of the output of configuration error messages.

Jpgraph 3.x supports three options

1. en (English error message)

2. de (German error message)

3. prod (application on the product server)

Just open the jpgraph class library configuration file jpg-config.inc.php and navigate

1
2
3
Define ('default _ ERR_LOCALE ', 'en ');
?>

Make changes.

In addition to modifying the jpgraph class library configuration file, you can also modify it by dynamically calling each program code. the method is as follows:

1
2
3
JpGraphError: SetErrLocale ($ aLocale );
?>

  Jpgraph class library and PHP configuration on the product server

In this part, because the target end user is a visitor, some modifications are required. most of the modifications are consistent with the jpgraph configuration on the development server. the jpgraph configuration is different in two aspects.

  Enable proper error levels

Displaying all error messages on the product server is not a wise decision. you should disable displaying all error messages and saving them in the diary file.

Modify the following options in the php. ini configuration file:

1
2
3
4
5
6
7
Display_errors = Off

Display_startup_errors = Off

Log_errors = On

Error_log =

Specifies the directory where log files are stored.

  Configure jpg-config-. inc. php

Configure the error information option of the jpgraph class library as prod, that is

1
2
3
Define ('default _ ERR_LOCALE ', 'prod ');
?>

  Adjust PHP include path

You can modify the configuration file PHP in two ways. ini and locate the include_path option to add the installation directory of the jpgraph class library, and add include_path in the PHP code header through the php_ini_set function.

The purpose of modifying include_path is to use include or require_once to include the convenience and uniformity of the jpgraph. php file.

Now, the detailed installation and configuration tutorial of the jpgraph class library is complete. modifying the PHP configuration file and the jpgraph configuration file can lay a solid foundation for future use of the jpgraph class library.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.