I don’t really read a whole lot of books. A friend mentioned this book to me in passing so I read it. I wouldn’t say it’s a life changer, but it definitely makes you want to step away from being an affiliate marketer and more towards owning an actual product. If you haven’t already, I suggest you get a copy and give it a read. Definitely some good information there on setting up an automated business that doesn’t require a whole lot of management (hence the book title) through private labeling, shipping handlers, etc.. There is also some probably not so good advice in there as well such as cutting people off when they need help so they learn to do it themselves. I’ve read a few blogs where people’s bosses decided to do this and they literally ran their company into the ground. Some businesses need more maintenance than others, just because this dude is getting away with 4 hours doesn’t mean you can.
Archive for June, 2008
The 4-Hour Workweek
June 6th, 2008Multi-threading PHP
June 4th, 2008If you know how to do this better let me know. Basically, when scraping data, I always try to have as many threads going as my bandwidth and server can handle. Scraping 1 page at a time is too damn slow. When I first tried threading I used pcntl_fork. This required me to recompile php with the plugin for it which began to become a pain in the ass. I like making my scripts work with the default php setup simply because if I ever decide to move the script I don’t want to be screwing around with php on the new server. With that said, I now use exec for everything which in my opinion works better anyway.
I have 2 files, the first is threadstart.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <?php $totalprocesses = 25; // How many threads you want to run at once $start = 1; $processes = 0; while($start > 0){ echo "Checking $start\n"; exec("(/usr/bin/php -q thread.php $start > /home/logs/thread.log) & /dev/null &"); $processes++; $start++; while($processes > ($totalprocesses - 1)){ $text = shell_exec("ps -Af | grep php"); preg_match_all('/thread.php/', $text, $matches); $processes = count($matches[0]); sleep(2); // You can change this to however fast you want to check if a thread is still going } } ?> |
thread.php
1 2 3 4 5 | <?php $argv[1]; // this is the $start variable you passed in the threadstart.php. Simply use this ID to do what you want. ?> |