Posted by Kelvin on 03 Feb 2014 | Tagged as: PHP
Here's one way to send and close the connection to the client and for the PHP script to continue processing, presumably to perform some processing that is time-consuming:
'Text user will see'"Content-Length: $size"// Strange behaviour, will not work
// Unless both are called !
//do processing here
'Text user will never see');
//do some processing
Note that some stackoverflow answers which mention the use of ignore_user_abort are mistaken. That's not required at all. And you'll need the Content-Encoding: none header, otherwise it won't work properly with clients that accept gzip encoding for example.
A more efficient implementation of curl_multi()
Installing Apache Worker over prefork.
I stumbled on this page when researching the pros/cons of Apache + mod_php vs nginx + php5-fpm
Nice posting about wordpress.com's use of nginx for load balancing.
At the moment (October 2011), there's no simple way to download all videos from a playlist from KhanAcademy.org.
This simple PHP crawler script changes that.
What it does is downloads the videos (from archive.org) to a subfolder, numbering and naming the videos with the respective titles (not the gibberish titles that archive.org has assigned them). Additionally, through the use of wget –continue, the crawler has auto-resume support, so even if your computer crashes in the middle of a crawl, you don't need to start all over again.
Usage is like this, assuming the script is named downkhan.php:
where folder is the subdirectory to save the videos in, and urls.txt is a list of urls obtained by running a regex on http://www.khanacademy.org/#browse.
The regex used was
Here is a few lines of a urls.txt file:
Here's a list of what I've created so far:
And here's the script:
$html = ""/<a href=\"(http:\/\/www.archive.org.*?)\"/""$counter. $title.mp4""$outfile"// initialize curl handle
// set url to post to
// allow redirects
// return into a variable
'Accept: */*', 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows)'// run the whole process
'Curl error: '/* return if already absolute URL */"/* queries and anchors */'#' || $rel == '?'/* parse base URL and convert to local variables:
$scheme, $host, $path *//* remove non-directory element from path */'#/[^/]*$#', ", $path);
/* destroy path if relative url points to root */'/') $path = ";
/* dirty absolute URL */"$host$path/$rel";
/* replace '//' or '/./' or '/foo/../' with '/' */'#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#''/'/* absolute URL is ready! */'://'
I recently discovered an Ajax CRUD library which makes CRUD operations positively painless: AjaxCRUD
Its features include:
– displaying list in an inline-editable table
– generates a create form
– all operations (add,edit,delete) handled via ajax
– supports 1:many relations
– only 1 class to include!!
I highly recommend you try it out!
Here is the example code:
# this one line of code is how you implement the class
# don't show the primary key in the table
# my db fields all have prefixes;
# display headers as reasonable titles
"fldFName", "First""fldLName", "Last""fldPaysBy", "Pays By""fldDescription", "Customer Info");
# set the height for my textarea
# define allowable fields for my dropdown fields
# (this can also be done for a pk/fk relationship)
"Cash", "Credit Card", "Paypal""fldPaysBy", $values);
# add the filter box (above the table)
# actually show to the table
"Content-Transfer-Encoding: base64\r\n""Content-Disposition: attachment; filename=\"""\"\r\n\r\n""\r\n\r\n""–".$uid."–""""mail send … OK"; // or use booleans here
"mail send … ERROR!";
Posted by Kelvin on 04 Dec 2010 | Tagged as: PHP
Ever wanted to format your XML nicely? Use the SimpleDOM class.
Usage is like so:
$xml = "<foo><bar>car</bar></foo>"
Am I the only guy using WordPress who is too lazy to type out anchors?
Well, I've been using a WordPress plugin I wrote to automagically linkify URLs for a number of years now, and finally decided to add it to Google Code.
So here it is! http://code.google.com/p/urlizer/
Modify .htaccess to include this:
The definitive answer is here: http://www.samtseng.liho.tw/~samtz/blog/2009/03/11/howto-build-the-php-rrdtool-extension/
If you're on Ubuntu, do this first:
Then follow the steps above.
The problem is described here:
I successfully tracked the problem to the "Connection:" header. It seems that
if the "Connection: keep-alive" request header is not sent the server will
respond with data which is not chunked . It will still reply with a
"Transfer-Encoding: chunked" response header though.
I don't think this behavior is normal and it is not a cURL problem. I'll
consider the case closed but if somebody wants to make something about it I
can send additional info and test it further.
The workaround is simple: have curl use HTTP version 1.0 instead of 1.1.
In PHP, add this: