CURL download speed is very slow on PHP Apache server

I have a service running on Apache server that use curl php to retrieve web pages ... . For unknown reasons, I notice that the download speed gets very slow. But it's not normal, since I issues ... :// ... , not only the download speed is slow, but also the DNS lookup time. DNS lookup took 13.1 seconds

PHP array_multisort two arrays sort by column example

A common problem we run into in day to day PHP programming is to sort two arrays by one ... column. Especially when the data comes from database. We sometimes need to write code to do the things ... from table order by a desc; SQL is a declaration language and good at such tasks, PHP is an imperative ... . There are several ported LINQ for PHP, check them out if you want to save your precious time

How to use CURL examples and tutorials

('error-curl.txt'); But you can read the file after the function that create and use the curl ... ::: Network is unreachable] The reason of network is unreachable can be the curl tries to use IPv6 ... [How to debug curl with CURLOPT_STDERR and CURLOPT_VERBOSE] Step 1, enable verbose ... mode in curl curl_setopt($ch, CURLOPT_VERBOSE, true); If the problem is connection timeout, you may

Use a plugin pattern in PHP instead of global variable

call it polymorphism. Its tempting to abuse a global variable in PHP to implement it. Declare ... is a solution I used to solve the global variable issue. [Instead of overwrite global variable, we ... . Using a global variable will be a disaster, the abstractions will leaks everywhere. Here ... can use a plugin] A plugin is an implementation can be plugged into a predefined place. And its

Call to undefined function mysql_connect

The reason of the problem is PHP didn't load php_msql.dll correct. Here is how to solve ... the problem. Print the output of phpinfo and search for Loaded Configuration File, and locate ... the configuration file: Open the file with your editor and search for extension_dir Make sure ... the path is right, usually it should point to ext directory of your PHP installation.

PHP date function

For example, I want date in this format

Use format string "Y-m-d"


format. preg_match('/line1\r\ntheme_name:([\s\S]*?)\r\nline3/', $text, $matches); The matches ... Match text between two lines, suppose we have three lines of text line1 theme_name:theme1 ... line3 We want to extract out the theme name, here the "theme1" string. We use windows line ending ... will looks like Array ( [0] => line1 theme_name:theme1 line3 [1] => theme1 )


Here is a sample html file contains only "p" and "div" tag:

And we want to insert content into the html, we don't want undermine the html structure, we wish to delimit it in terms of html element, not just characters. We also want to know the positions we want to insert the content. We can use PREG_OFFSET_CAPTURE:

Simple PHP performance profiling

One day you found that the page takes almost one minute to load. And it not happened before. You don't know which part of your program get a performance bottleneck. But some complex sql queries looks suspicious.

You want to know how much time elapsed for each of these queries.

Display output of PHP print_r in HTML

Both echo and print_r are widely used in day to day PHP programming, but raw print_r is very unfriendly to HTML display which is the de facto output interface in web developing environment.

Most PHPer may have tried at some moments in their career life to make their own version of a wrapper of print_r to make it HTML friendly. Here are some handy code that I used for my tasks, they are truly great life savers at some particular moments.

Most PHPer may have tried at some moments in their career life to make their own version of a wrapper of print_r to make it HTML friendly. .

1 2 ... 4 Next Page