### MySQLi Quickstart and Connections Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html A quick start guide for using the MySQLi extension in PHP. Covers dual interface (object-oriented and procedural), connection handling, and common coding styles. ```php ``` ```php ``` ```php ``` ```php ``` ```php ``` -------------------------------- ### PHP Stream Context Management Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Illustrates how to create, get default, get options, get parameters, and set default/options for stream contexts in PHP. ```php ``` ```php array( 'method' => "GET", 'header' => "User-Agent: MyCustomClient/1.0\r\n" ) ); $context = stream_context_create($options); // Use the context with a stream function, e.g., file_get_contents // $file = file_get_contents('http://example.com', false, $context); ?> ``` ```php ``` ```php array('timeout' => 5), 'ssl' => array('verify_peer' => false) ); $context = stream_context_create($options); $http_options = stream_context_get_options($context, 'http'); print_r($http_options); ?> ``` ```php function($notification_code, $severity, $message, $bytes_transferred, $bytes_max) { // Handle notification } ); $context = stream_context_create($options); $params = stream_context_get_params($context); // print_r($params); ?> ``` ```php ['user_agent' => 'MyAgent']]); stream_context_set_default($new_default_context); // Subsequent stream operations will use this new default context if none is specified. ?> ``` ```php ``` -------------------------------- ### LSPHP Command Line Execution Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/install.unix.litespeed.html Demonstrates how to start the LSPHP executable from the command line, binding to different network interfaces or Unix domain sockets, and setting environment variables for configuration. ```bash # Bind to all IPv4 and IPv6 addresses on port 3000 /path/to/lsphp -b [::]:3000 # Bind to all IPv4 addresses on port 3000 /path/to/lsphp -b *:3000 # Bind to a specific IP address and port /path/to/lsphp -b 192.168.0.2:3000 # Bind to a Unix domain socket /path/to/lsphp -b /tmp/lsphp_manual.sock # Set environment variables before execution PHP_LSAPI_MAX_REQUESTS=500 PHP_LSAPI_CHILDREN=35 /path/to/lsphp -b IP_address:port ``` -------------------------------- ### GnuPG Configuration and Initialization Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Illustrates initializing GnuPG with default settings and custom configurations (file name, home directory) using both procedural and object-oriented styles in PHP. ```php ``` ```php ``` ```php ``` ```php ``` -------------------------------- ### Example: Get Start Date from DatePeriod Object in PHP Source: https://github.com/fmatsos/php-doc/blob/main/doc/dateperiod.getstartdate.html This PHP example demonstrates how to instantiate a `DatePeriod` object using a recurrence rule string and then retrieve its start date using the `getStartDate()` method. The retrieved `DateTime` object is subsequently formatted into ISO8601 string and echoed, showing the initial date of the period. ```php getStartDate(); echo $start->format(DateTime::ISO8601); ?> ``` -------------------------------- ### PHP array_slice Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Provides examples of the array_slice() function, which extracts a portion of an array. It can be used to get a sub-array based on starting index and length. ```php ``` ```php 'a', 2 => 'b', 3 => 'c', 4 => 'd', 5 => 'e'); $result = array_slice($array, 2, -1); print_r($result); ?> ``` ```php "val1", "bar" => "val2", "baz" => "val3", "qux" => "val4"); $output = array_slice($input, 1, 2); print_r($output); ?> ``` -------------------------------- ### MySQL API Comparison and Configuration Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Compares different MySQL APIs and discusses configuration options. Includes examples for choosing between mysqlnd and libmysqlclient, and understanding prepared statements versus direct queries. ```php ``` ```php ``` ```php ``` -------------------------------- ### PECL Extension Installation Guide Source: https://github.com/fmatsos/php-doc/blob/main/doc/xattr.installation.html Provides guidance on installing PECL extensions, including links to requirements, constants, setup, and the PECL package page. Notes the unavailability of a DLL for Windows builds. ```php /* * Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. * Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: https://pecl.php.net/package/xattr * A DLL for this PECL extension is currently unavailable. See also the building on Windows section. */ ``` -------------------------------- ### ResourceBundle::create Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Shows how to create a ResourceBundle, with procedural and object-oriented examples. ```php ``` -------------------------------- ### PHP ImagickDraw: Path and Point Drawing Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Demonstrates starting a path and drawing a point using ImagickDraw::pathStart and ImagickDraw::point. ```php ``` -------------------------------- ### PHP floatval() Non-numeric Example Source: https://github.com/fmatsos/php-doc/blob/main/doc/function.floatval.html Illustrates the behavior of floatval() when the string does not start with a numeric character. In such cases, the function returns 0. ```php // Output: 0 ``` -------------------------------- ### Yaf Application Entry Point (index.php) Source: https://github.com/fmatsos/php-doc/blob/main/doc/yaf.tutorials.html This snippet shows the main entry point for a Yaf application. It defines the application path, instantiates Yaf_Application with the configuration file, and runs the application bootstrap process. ```php bootstrap() //call bootstrap methods defined in Bootstrap.php ->run(); ?> ``` -------------------------------- ### PECL Extension Installation Guide Source: https://github.com/fmatsos/php-doc/blob/main/doc/openal.installation.html Provides instructions and links for installing a PECL extension. It directs users to the PECL website for detailed information and mentions the availability of installation guides for different platforms. ```APIDOC PECL Extension Installation: - Not bundled with PHP. - Refer to the manual chapter 'Installation of PECL extensions' for installation information. - Additional information (releases, downloads, source files, maintainer info, CHANGELOG) available at: https://pecl.php.net/package/openal - DLL for Windows is currently unavailable. See 'building on Windows' section. ``` -------------------------------- ### PHP Example: Using mysql_xdevapi\Session::commit for Transactions Source: https://github.com/fmatsos/php-doc/blob/main/doc/mysql-xdevapi-session.commit.html This PHP example demonstrates the usage of `mysql_xdevapi\Session::commit` within a transaction. It shows how to establish a session, get a collection, start a transaction, add data, set a savepoint, commit the transaction, and finally close the session. ```PHP $session = mysql_xdevapi\getSession("mysqlx://user:password@localhost"); $collection = $session->getSchema("addressbook")->getCollection("friends"); $session->startTransaction(); $collection->add('{"John":42, "Sam":33}')->execute(); $savepoint = $session->setSavepoint(); $session->commit(); $session->close(); ``` -------------------------------- ### InterBase Connection and Query Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Demonstrates how to establish a connection to an InterBase database using ibase_connect and execute queries using ibase_execute. Includes examples for fetching data with ibase_fetch_object and retrieving field information with ibase_field_info. ```php ``` -------------------------------- ### PHP Memcache Connect Example Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Illustrates how to establish a connection to a Memcache server. ```php connect('localhost', 11211)) { echo "Connected to Memcache server.\n"; } else { echo "Failed to connect to Memcache server.\n"; } ?> ``` -------------------------------- ### MySQL X DevAPI: Connection and Schema Management Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Demonstrates establishing a connection to a MySQL server using a URI and managing schemas and collections. Includes examples for creating schemas, collections, and checking for their existence. ```php createSchema("my_schema"); $collection = $schema->createCollection("my_collection"); if ($collection->existsInDatabase()) { echo "Collection exists."; } ?> ``` -------------------------------- ### PHP Example: Getting Stomp Extension Version Source: https://github.com/fmatsos/php-doc/blob/main/doc/function.stomp-version.html Demonstrates how to call the `stomp_version` function in PHP to retrieve and display the installed version of the Stomp extension using `var_dump`. ```PHP ``` -------------------------------- ### PHP Win32Service Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Shows how to manage Windows services using PHP, including registering, unregistering, and running scripts as services. ```php Registering a PHP script to run as a service Unregistering a service Running as a service ``` -------------------------------- ### PHP ob_get_length() Example Source: https://github.com/fmatsos/php-doc/blob/main/doc/function.ob-get-length.html Demonstrates how to use ob_get_length() to get the length of the output buffer at different stages of output buffering. It starts buffering, echoes content, retrieves lengths, and then cleans the buffer. ```php ``` -------------------------------- ### PHP OCI8: Establishing Database Connections with oci_connect Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Covers various methods for establishing database connections using `oci_connect`, including Easy Connect syntax, Network Connect names, explicit character sets, and using multiple connections. ```php ``` -------------------------------- ### Install PECL Extensions Source: https://github.com/fmatsos/php-doc/blob/main/doc/tcpwrap.installation.html General information on installing PECL extensions, as referenced in the tcpwrap installation guide. ```php include "install.pecl.html"; ``` -------------------------------- ### PHP Gender Functions Source: https://github.com/fmatsos/php-doc/blob/main/doc/refs.international.html Documents the Gender extension in PHP, which is used to determine the gender of first names. It includes an introduction, installation guide, examples, and the Gender\Gender class. ```php Gender\Gender::guess() ``` -------------------------------- ### QuickHashIntSet Operations Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Demonstrates the usage of the QuickHashIntSet class for managing sets of integers. Includes examples for adding, deleting, checking existence, getting size, and loading/saving data from files or strings. ```php add(10); // $intSet->add(20); // QuickHashIntSet::__construct example // $initial_data = [1, 2, 3]; // $intSet_constructed = new QuickHashIntSet($initial_data); // QuickHashIntSet::delete example // $intSet->delete(10); // QuickHashIntSet::exists example // if ($intSet->exists(20)) { // echo "20 exists in the set.\n"; // } // QuickHashIntSet::getSize example // echo "Set size: " . $intSet->getSize() . "\n"; // QuickHashIntSet::loadFromFile example // $intSet->loadFromFile('data.set'); // QuickHashIntSet::loadFromString example // $set_string = "1,2,3,4"; // $intSet->loadFromString($set_string); // QuickHashIntSet::saveToFile example // $intSet->saveToFile('output.set'); // QuickHashIntSet::saveToString example // $set_as_string = $intSet->saveToString(); ?> ``` -------------------------------- ### Stomp Constructor Example Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Shows how to instantiate the Stomp client using both object-oriented and procedural styles. ```php ``` ```php ``` -------------------------------- ### PHP OCI8 Connection String Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/oci8.installation.html Demonstrates how to connect to Oracle databases using PHP's OCI8 extension. It covers both Easy Connect syntax and the use of tnsnames.ora configuration files. ```php oci_connect("username", "password", "//localhost/XE"); // or using tnsnames.ora entry ociconnect("username", "password", "MYTNSENTRY"); ``` -------------------------------- ### eio_statvfs() example Source: https://github.com/fmatsos/php-doc/blob/main/doc/function.eio-statvfs.html Example demonstrating the usage of eio_statvfs to get file system statistics and process them in a callback function. ```php ``` -------------------------------- ### ResourceBundle::get Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Demonstrates retrieving data from a ResourceBundle, with procedural and object-oriented examples. ```php ``` -------------------------------- ### Configure PHP.ini to Load FANN Extension Source: https://github.com/fmatsos/php-doc/blob/main/doc/fann.installation.html Instruction to modify the 'php.ini' configuration file to enable the FANN PHP extension. Adding this line ensures that the extension is loaded automatically when PHP starts. ```PHP extension=fann.so ``` -------------------------------- ### QuickHash Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Provides examples for using the QuickHash library, including basic operations, ArrayAccess, Iterator, and handling string values. Demonstrates efficient hashing and data manipulation. ```php add('key1', 'value1'); // echo $hash->get('key1'); // Quickhash ArrayAccess Example // if ($hash instanceof ArrayAccess) { // echo $hash['key1']; // $hash['key2'] = 'value2'; // } // Quickhash Iterator Example // if ($hash instanceof Iterator) { // foreach ($hash as $key => $value) { // echo "$key: $value\n"; // } // } // Quickhash String Values Example // $hash_string = new QuickHash(); // $hash_string->add('name', 'Alice'); // $hash_string->add('age', 30); // echo $hash_string->toString(); // Example method ?> ``` -------------------------------- ### WinCache Configuration Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Examples for configuring WinCache, including ignore lists and authentication. ```php ; Example for wincache.ignorelist ignorelist = "/tmp/cache/*" ``` ```php ; Example for authentication configuration authentication = "user:password" ``` -------------------------------- ### PHP Simple HTTP Server Setup Source: https://github.com/fmatsos/php-doc/blob/main/doc/event.examples.html Configures a simple HTTP server using EventHttp, allowing GET and POST methods, and setting callbacks for specific URIs ('/dump', '/about') and a default handler. ```php = $max_requests) { echo "Counter reached max requests $max_requests. Exiting\n"; exit(); } echo __METHOD__, " called\n"; echo "request:"; var_dump($req); echo "data:"; var_dump($data); echo "\n===== DUMP =====\n"; echo "Command:", $req->getCommand(), PHP_EOL; echo "URI:", $req->getUri(), PHP_EOL; echo "Input headers:"; var_dump($req->getInputHeaders()); echo "Output headers:"; var_dump($req->getOutputHeaders()); echo "\n >> Sending reply ..."; $req->sendReply(200, "OK"); echo "OK\n"; echo "\n >> Reading input buffer ...\n"; $buf = $req->getInputBuffer(); while ($s = $buf->readLine(EventBuffer::EOL_ANY)) { echo $s, PHP_EOL; } echo "No more data in the buffer\n"; } function _http_about($req) { echo __METHOD__, PHP_EOL; echo "URI: ", $req->getUri(), PHP_EOL; echo "\n >> Sending reply ..."; $req->sendReply(200, "OK"); echo "OK\n"; } function _http_default($req, $data) { echo __METHOD__, PHP_EOL; echo "URI: ", $req->getUri(), PHP_EOL; echo "\n >> Sending reply ..."; $req->sendReply(200, "OK"); echo "OK\n"; } $port = 8010; if ($argc > 1) { $port = (int) $argv[1]; } if ($port <= 0 || $port > 65535) { exit("Invalid port"); } $base = new EventBase(); $http = new EventHttp($base); $http->setAllowedMethods(EventHttpRequest::CMD_GET | EventHttpRequest::CMD_POST); $http->setCallback("/dump", "_http_dump", array(4, 8)); $http->setCallback("/about", "_http_about"); $http->setDefaultCallback("_http_default", "custom data value"); $http-> ``` -------------------------------- ### PHP POSIX Functions Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Showcases examples for POSIX-related functions, including file access, environment information, and path configuration. ```php ``` -------------------------------- ### SNMP Get and GetNext (Generic) Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Examples for performing generic SNMP get and getnext operations, including fetching single or multiple OIDs. ```php ``` ```php ``` -------------------------------- ### Advanced Event Loop and Server Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Showcases advanced event loop usage, such as processing requests with the 'eio' extension, and setting up a simple HTTP server. ```php // Use libevent's loop to process requests of `eio' extension // Miscellaneous // Simple HTTP server ``` -------------------------------- ### PHP Features: CLI Usage and Scripts Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Demonstrates how to execute PHP scripts from the command line, including creating batch files and understanding script usage. ```PHP features.commandline.usage.html#example-552 features.commandline.usage.html#example-553 ``` -------------------------------- ### PHP mysqlnd Proxy Connection Example Source: https://github.com/fmatsos/php-doc/blob/main/doc/mysqlnd.plugin.developing.html Demonstrates how to create a proxy class extending mysqlnd_plugin_connection to intercept and modify connection and query behavior. It shows how to use 'pre' and 'post' hooks for custom logic. ```php class proxy extends mysqlnd_plugin_connection { public function connect($conn, $host, ...) { /* "pre" hook */ printf("Connecting to host = '%s'\n", $host); debug_print_backtrace(); return parent::connect($conn); } public function query($conn, $query) { /* "post" hook */ $ret = parent::query($conn, $query); printf("Query = '%s'\n", $query); return $ret; } } mysqlnd_plugin_set_conn_proxy(new proxy()); ``` -------------------------------- ### Retrieve MySQL Host Info (Object-Oriented PHP) Source: https://github.com/fmatsos/php-doc/blob/main/doc/mysqli.get-host-info.html This PHP example demonstrates how to use the `mysqli::$host_info` property to get connection details in an object-oriented style, including error reporting setup and printing the host information. ```PHP host_info); ?> ``` -------------------------------- ### YAF Framework Examples Source: https://github.com/fmatsos/php-doc/blob/main/doc/indexes.examples.html Provides examples for various components of the YAF (Yet Another Framework) PHP framework, including application setup, configuration, and dispatching. ```php ``` ```php run(); ?> ``` ```php ``` ```php ``` ```php ``` ```php ``` ```php run(); ?> ``` ```php 'value1', // 'key2' => 'value2' // )" ?> ``` ```php ``` ```php setView($view); } public function _initRoute() { // Initialize routes } public function _initError() { // Initialize error handling } } ?> ``` ```php bootstrap(); // Calls all _init* methods in Bootstrap ?> ``` ```php clearLastError(); ?> ``` ```php ``` ```php environ(); // Returns the current environment (e.g., 'product', 'develop') ?> ``` ```php execute('Index::indexAction'); // Executes a specific action ?> ``` ```php getConfig(); // echo $config->get('application.directory'); ?> ``` ```php getDispatcher(); // $dispatcher->returnResponse(true); ?> ``` ```php getLastErrorMsg(); ?> ``` ```php getLastErrorNo(); ?> ``` ```php getModules()); ?> ``` ```php setView($view); // } // } ?> ``` ```php autoRender(false); // Disable auto rendering ?> ``` ```php catchException(true); // Enable exception catching ?> ``` ```php registerPlugin($plugin); ?> ``` ```php setView($view); ?> ``` ```php throwException(true); // Throw exceptions instead of handling them internally ?> ``` ```php get('config.ini.host'); ?> ``` -------------------------------- ### PHP Example: Accessing Ds\Vector Elements with get() Method Source: https://github.com/fmatsos/php-doc/blob/main/doc/ds-vector.get.html Demonstrates how to retrieve elements from a `Ds\Vector` using the `get()` method. This example initializes a vector and then uses `get()` with different indices to fetch and display the corresponding values. ```PHP get(0)); var_dump($vector->get(1)); var_dump($vector->get(2)); ?> ```