PHP cURL command line app not waiting for response

Alec Jacobson

September 17, 2012

weblog/

I had written a PHP command line app that took a URL as a command line argument:
php foo.php http://www.nytimes.com/2012/09/16/arts/shock-me-if-you-can.html?ref=arts&pagewanted=all 
The foo.php was simply calling curl to grab the page in question, do a little parsing and then spit it back out. When I issued the command above though, the program seemed to finish immediately and then later spit out the results. I was left thinking that the curl commands were asynchronous. It turned out to be much simpler. I had an ampersand (&) in the url argument. This was forking the process in my bash terminal. All I needed to do was put quotes around the argument:
php foo.php "http://www.nytimes.com/2012/09/16/arts/shock-me-if-you-can.html?ref=arts&pagewanted=all"