December 19th, 2007
Reference: Some Configuration Macros 355 Additional API Macros Shortly before the release of this book, a new set of macros was introduced into Zend s API that simplify access to zval containers (see Table 9.19). However, we chose not to use them in the example sources, as they don t make many accesses to zval containers, and the macros would have resulted in source code that was more difficult to read. Table 9.19 New API macros for Accessing zval Containers Macro Refers to Z_LVAL(zval)(zval).value.lval Z_DVAL(zval)(zval).value.dval Z_STRVAL(zval)(zval).value.str.val Z_STRLEN(zval)(zval).value.str.len Z_ARRVAL(zval)(zval).value.ht Z_LVAL_P(zval) (*zval).value.lval Z_DVAL_P(zval) (*zval).value.dval Z_STRVAL_P(zval_p) (*zval).value.str.val Z_STRLEN_P(zval_p) (*zval).value.str.len Z_ARRVAL_P(zval_p) (*zval).value.ht Z_LVAL_PP(zval_pp) (**zval).value.lval Z_DVAL_PP(zval_pp) (**zval).value.dval Z_STRVAL_PP(zval_pp) (**zval).value.str.val Z_STRLEN_PP(zval_pp) (**zval).value.str.len Z_ARRVAL_PP(zval_pp) (**zval).value.ht Updates of this chapter can be found at www.phpwizard.net.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.
Posted in MySQL | No Comments »
December 18th, 2007
354 Chapter 9 Extending PHP 4.0: Hacking the Core of PHP Reference: Some Configuration Macros config.m4 The file config.m4 is processed by buildconf and must contain all the instructions to be executed during configuration. For example, these can include tests for required external files, such as header files, libraries, and so on. PHP defines a set of macros that can be used in this process, the most useful of which are described in Table 9.18. Table 9.18 M4 Macros for config.m4 Macro Description AC_MSG_CHECKING(message) Prints a checking text during configure. AC_MSG_RESULT(value) Gives the result to AC_MSG_CHECKING; should specify either yes or no as value. AC_MSG_ERROR(message) Prints message as error message during configure and aborts the script. AC_DEFINE(name, value, description) Adds #define to php_config.h with the value of value and a comment that says description (this is useful for conditional compilation of your module). AC_ADD_INCLUDE(path) Adds a compiler include path; for example, used if the module needs to add search paths for header files. AC_ADD_LIBRARY_WITH_PATH Specifies an additional library to link. (libraryname, librarypath) AC_ARG_WITH(modulename, description, Quite a powerful macro, adding the module unconditionaltest, conditionaltest) with description to the configure –help output. PHP checks whether the option –with- is given to the configure script. If so, it runs the script unconditionaltest (for example, –with-myext=yes), in which case the value of the option is contained in the variable $withval. Otherwise, it executes conditionaltest. PHP_EXTENSION(modulename, [shared]) This macro is a must to call for PHP to configure your extension.You can supply a second argument in addition to your module name, indicating whether you intend compilation as a shared module.This will result in a definition at compile time for your source as COMPILE_DL_.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.
Posted in MySQL | No Comments »
December 18th, 2007
Where to Go from Here 353 Macro Description INI_BOOL(name) Returns the current value of entry name as Boolean (defined as zend_bool, which currently means unsigned char). INI_ORIG_INT(name) Returns the original value of entry name as integer (long). INI_ORIG_FLT(name) Returns the original value of entry name as float (double). INI_ORIG_STR(name) Returns the original value of entry name as string. Note: This string is not duplicated, but instead points to internal data. Further access requires duplication to local memory. INI_ORIG_BOOL(name) Returns the original value of entry name as Boolean (defined as zend_bool, which currently means unsigned char). Finally, you have to introduce your initialization entries to PHP.This can be done in the module startup and shutdown functions, using the macros REGISTER_INI_ENTRIES() and UNREGISTER_INI_ENTRIES(): ZEND_MINIT_FUNCTION(mymodule) { REGISTER_INI_ENTRIES(); } ZEND_MSHUTDOWN_FUNCTION(mymodule) { UNREGISTER_INI_ENTRIES(); } Where to Go from Here You ve learned a lot about PHP. You now know how to create dynamic loadable modules and statically linked extensions.You ve learned how PHP and Zend deal with internal storage of variables and how you can create and access these variables.You know quite a set of tool functions that do a lot of routine tasks such as printing informational texts, automatically introducing variables to the symbol table, and so on. Even though this chapter often had a mostly referential character, we hope that it gave you insight on how to start writing your own extensions. For the sake of space, we had to leave out a lot; we suggest that you take the time to study the header files and some modules (especially the ones in the ext/standard directory and the MySQL module,as these implement commonly known functionality).This will give you an idea of how other people have used the API functions particularly those that didn t make it into this chapter.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.
Posted in MySQL | No Comments »
December 17th, 2007
352 Chapter 9 Extending PHP 4.0: Hacking the Core of PHP The fourth parameter consists of a pointer to a change-notification handler. Whenever one of these initialization entries is changed, this handler is called. Such a handler can be declared using the PHP_INI_MH macro: PHP_INI_MH(OnChangeSecond); // handler for ini-entry . second_ini_entry // specify ini-entries here PHP_INI_MH(OnChangeSecond) { zend_printf( Message caught, our ini entry has been changed to %s
, .new_value); return(SUCCESS); } The new value is given to the change handler as string in the variable new_value. When looking at the definition of PHP_INI_MH, you actually have a few parameters to use: #define PHP_INI_MH(name) int name(php_ini_entry *entry, char *new_value, .uint *new_value_length, void *mh_arg1, .void *mh_arg2, void *mh_arg3) All these definitions can be found in php_ini.h.Your message handler will have access to a structure that contains the full entry, the new value, its length, and three optional arguments.These optional arguments can be specified with the additional macros PHP_INI_ENTRY1 (allowing one additional argument), PHP_INI_ENTRY2 (allowing two additional arguments), and PHP_INI_ENTRY3 (allowing three additional arguments). The change-notification handlers should be used to cache initialization entries locally for faster access or to perform certain tasks that are required if a value changes. For example, if a constant connection to a certain host is required by a module and someone changes the hostname, automatically terminate the old connection and attempt a new one. Access to initialization entries can also be handled with the macros shown in Table 9.17. Table 9.17 Macros to Access Initialization Entries in PHP Macro Description INI_INT(name) Returns the current value of entry name as integer (long). INI_FLT(name) Returns the current value of entry name as float (double). INI_STR(name) Returns the current value of entry name as string. Note: This string is not duplicated, but instead points to internal data. Further access requires duplication to local memory.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.
Posted in MySQL | No Comments »
December 17th, 2007
Calling User Functions 351 print( Return value: $return_value
); ?> Figure 9.11 Calling user functions. Initialization File Support PHP 4.0 features a redesigned initialization file support. It s now possible to specify default initialization entries directly in your code, read and change these values at runtime, and create message handlers for change notifications. To create an .ini section in your own module, use the macros PHP_INI_BEGIN() to mark the beginning of such a section and PHP_INI_END() to mark its end. In between you can use PHP_INI_ENTRY() to create entries. PHP_INI_BEGIN() PHP_INI_ENTRY( first_ini_entry , has_string_value , PHP_INI_ALL, NULL) PHP_INI_ENTRY( second_ini_entry , 2 , PHP_INI_SYSTEM, .OnChangeSecond) PHP_INI_ENTRY( third_ini_entry , xyz , PHP_INI_USER, NULL) .PHP_INI_END() The PHP_INI_ENTRY() macro accepts four parameters: the entry name, the entry value, its change permissions, and a pointer to a change-notification handler. Both entry name and value must be specified as strings, regardless of whether they really are strings or integers. The permissions are grouped into three sections: PHP_INI_SYSTEM allows a change only directly in the php3.ini file; PHP_INI_USER allows a change to be overridden by a user at runtime using additional configuration files, such as .htaccess); and PHP_INI_ALL allows changes to be made without restrictions.There s also a fourth level, PHP_INI_PERDIR, for which we couldn t verify its behavior yet.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.
Posted in MySQL | No Comments »
December 16th, 2007
350 Chapter 9 Extending PHP 4.0: Hacking the Core of PHP Listing 9.16 and Figure 9.11 show a small demonstration of calling a user function. The code calls a function that s supplied to it as argument and directly passes this function s return value through as its own return value. Note the use of the constructor and destructor calls at the end it might not be necessary to do it this way here (since they should be separate values, the assignment might be safe), but this is bulletproof. Listing 9.16 Calling user functions. zval **function_name; zval *retval; if((ZEND_NUM_ARGS() != 1) || (zend_get_parameters_ex(1, &function_name) .!= SUCCESS)) { WRONG_PARAM_COUNT; } if((*function_name)->type != IS_STRING) { zend_error(E_ERROR, Function requires string argument ); } CLS_FETCH(); if(call_user_function_ex(CG(function_table), NULL, *function_name, &retval, .0, NULL, 0) != SUCCESS) { zend_error(E_ERROR, Function call failed ); } zend_printf( We have %i as type
, retval->type); *return_value = *retval; zval_copy_ctor(return_value); zval_dtor(retval); ); return( hello ); } $return_value = call_userland( test_function );
We recommend high quality webhost to host and run your jsp application: christian web host services.
Posted in MySQL | No Comments »
December 15th, 2007
Calling User Functions 349 For dynamic extensions, module and request startup/shutdown events happen at the same time. Declaration and implementation of these functions can be done with macros; see the earlier section Declaration of the Zend Module Block for details. Calling User Functions You can call user functions from your own modules, which is very handy when implementing callbacks - for example, for array walking, searching, or simply for event-based programs. User functions can be called with the function call_user_function_ex().It requires a hash value for the function table you want to access, a pointer to an object (if you want to call a method), the function name, return value, number of arguments, argument array, and a flag indicating whether you want to perform zval separation: ZEND_API call_user_function_ex(HashTable *function_table, zval *object, .zval *function_name, zval **retval_ptr_ptr, .int param_count, zval **params[] .int no_separation); Notice that you don t have to specify both function_table and object; either will do. If you want to call a method, you have to supply the object that contains this method, in which case call_user_function() automatically sets the function table to this object s function table. Otherwise, you only need to specify function_table and can set object to NULL. Usually, the default function table is the root function table containing all function entries.This function table is part of the compiler globals and can be accessed using the macro CG.To introduce the compiler globals to your function, call the macro CLS_FETCH once. The function name is specified in a zval container.This might be a bit surprising at first, but is quite a logical step, since most of the time you ll accept function names as parameters from calling functions within your script, which in turn are contained in zval containers again.Thus,you only have to pass your arguments through to this function.This zval must be of type IS_STRING. The next argument consists of a pointer to the return value.You don t have to allocate memory for this container; the function will do so by itself. However, you have to destroy this container (using zval_dtor()) afterward! Next is the parameter count as integer and an array containing all necessary parameters.The last argument specifies whether the function should perform zval separation this should always be set to 0. If set to 1, the function consumes less memory but fails if any of the parameters need separation.
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.
Posted in MySQL | No Comments »
December 15th, 2007
348 Chapter 9 Extending PHP 4.0: Hacking the Core of PHP executed, use zend_get_executed_filename().This function accesses the executor globals, which are passed to it using the ELS_C macro.The executor globals are automatically available to every function that s called directly by Zend (they re part of the INTERNAL_FUNCTION_PARAMETERS described earlier in this chapter). If you want to access the executor globals in another function that doesn t have them available automatically, call the macro ELS_FETCH() once in that function; this will introduce them to your local scope. Finally, the line number currently being executed can be retrieved using the function zend_get_executed_lineno().This function also requires the executor globals as arguments. For examples of these functions, see Listing 9.15 and Figure 9.10. Of course, all the examples are also available on the CD-ROM. Listing 9.15 Printing execution information. zend_printf( The name of the current function is %s
, .get_active_function_name()); zend_printf( The file currently executed is %s
, .zend_get_executed_filename(ELS_C)); zend_printf( The current line being executed is %i
, .zend_get_executed_lineno(ELS_C)); Figure 9.10 Printing execution information. Startup and Shutdown Functions Startup and shutdown functions can be used for one-time initialization and deinitialization of your modules.As discussed earlier in this chapter (see the description of the Zend module descriptor block), there are global, module, and request startup and shutdown events. The global startup functions are called once when PHP starts up, similarly the global shutdown functions are called once when PHP shuts down. Please note that they re really only called once, not when a new Apache process is being created! The module startup and shutdown functions are called whenever a module is loaded and needs initialization; the request startup and shutdown functions are called every time a request is processed (meaning that a file is being executed).
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.
Posted in MySQL | No Comments »
December 14th, 2007
Printing Information 347 Typically, you can print an HTML table header using php_info_print_table_start() and then use the standard functions php_info_print_table_header() and php_info_print_table_row().As arguments, both take the number of columns (as integers) and the column contents (as strings). Listing 9.14 shows a source example;Figure 9.9 shows the output.To print the table footer, use php_info_print_table_end(). Listing 9.14 Source code and output in phpinfo( ). php_info_print_table_start(); php_info_print_table_header(2, First column , Second column ); php_info_print_table_row(2, Entry in first row , Another entry ); php_info_print_table_row(2, Just to fill , another row here ); php_info_print_table_end(); Figure 9.9 Output from phpinfo(). Execution Information You can also print execution information,such as the current file being executed.The name of the function currently being executed can be retrieved using the function get_active_function_name().This function returns a pointer to the function name and doesn t accept any arguments.To retrieve the name of the file currently being
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.
Posted in MySQL | No Comments »
December 14th, 2007
346 Chapter 9 Extending PHP 4.0: Hacking the Core of PHP Table 9.16 Zend s Predefined Error Messages Error Description E_ERROR Signals an error and terminates execution of the script immediately. E_WARNING Signals a generic warning. Execution continues. E_PARSE Signals a parser error. Execution continues. E_NOTICE Signals a notice. Execution continues. Note that by default the display of this type of error messages is turned off in php.ini. E_CORE_ERROR Internal error by the core; shouldn t be used by user-written modules. E_COMPILE_ERROR Internal error by the compiler; shouldn t be used by user-written modules. E_COMPILE_WARNING Internal warning by the compiler; shouldn t be used by user-written modules. Figure 9.8 Display of warning messages in the browser. Including Output in phpinfo( ) After creating a real module, you ll want to show information about the module in phpinfo() (in addition to the module name, which appears in the module list by default). PHP allows you to create your own section in the phpinfo() output with the ZEND_MINFO() function.This function should be placed in the module descriptor block (discussed earlier) and is always called whenever a script calls phpinfo(). PHP automatically prints a section in phpinfo() if you specify the ZEND_MINFO function, including the module name in the heading. Everything else must be formatted and printed by you.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.
Posted in MySQL | No Comments »