- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Yeah, this is forking not threading.
Admin
In fact, just looking at the code again, this is pretty absurd, shouldn't tell people to do stuff like that because it's.. bad in every way.
There are proper ways of forking process y'know? Maybe they aren't beautiful but they're better than this.
Admin
This is actually kind of an interesting hack, in my opinion. Each image could actually be a segment in a progress graphic.
Only problem is that it's completely unreliable. And you have no way of knowing when (or if) it ever completes.
Admin
My god, I nearly threw up.
The sad part is, I did this once, but it was just a quick hack when I wanted to call a script on someone else's page 5000 times. Not production code, but rather "I want to do something just for fun so I'll just hack up a script in 5 minutes and go play Nintendo while the computer chews on it".
Using this in production code would be a real WTF.
Admin
There is actually a way to support threads using PHP! It's been available since PHP 4.07, and it's basically the same way you do it in C, using a "fork" function. Here's a snippet that shows how to do this:
<?php $pid = pcntl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { // we are the parent; do parent stuff pcntl_wait($status); //Protect against Zombie children } else { // we are the child; do child stuff } ?>What happens is when we call the pcntl_fork() function, a child process that differs from the parent process only in its PID and PPID is created (ie, they share the same code). When the parent process issues the pcntl_fork() call, $pid holds the child's process id. When the child issues the pcntl_fork() call, $pid will hold 0. This way, we can distinguish who the parent is and who the child is and make them do different things.
Admin
Mulitthreading is something different from multiprocessing
Admin
Wow, am I really the only one that noticed 'weight' in the code instead of 'height'??
Admin
Yeah brilliant way "to do" multi-threading... Even though the only resemblance this would have with multi-threading is that more than one process is being run the same time as the other.
But then again you don't have to think about this since you're using your no-limit Markup Language CF.
gw FUD-monger stick to your unlimited language - ColdFusion cues "no-limit" music
Admin
yes. that means you're special. go knock the guy down some more. I'm sure you've never misspelt a word...
Admin
I do realize that. The presumption is that the server is set up in a certain way you have no control over. Think shared hosting.
Cheers!
Admin
The REAL, REAL WTF is image caching :)
Admin
http://dev.pedemont.com/sonic/
threads forks, same shite on the outside
Admin
I think the better option is to do this in a oop fashion. Nothing wrong with using a web-browser to do the multi-threading if you dont know how it gets the task accomplished just as if you did something command line. As far as the time out issues goes, there is a method that will allow a php script to reset the timeout on a server. I have a web crawler that does just this and will run indefinitely if I so choose to let it.
My web crawler is probably one of the best examples to the need or use of mutli threading and the time out issue. It also runs with a mysql-db back-end for recording various results, its work log, and its work que(which is different from the log). I make use of classes, objects, and the even some defines in my code(mostly for readability and re-usability).
Im starting a long series of tutorials on it on my site if it helps anyone Chris McIntosh Designs just take a look under the computer tutorial section.
As far as cold fusion or any language being better than another I believe that is all hog wash. it is not the language as so much as it is the programmer's familiarity with the language he is using. I have done some amazing things with just actionscript that would be a rival to things you can do in php, asp, or cf all of which I have programming expertise in. Anyway, keep the bias for languages down and think more as a engineer and use lots of placebo-code to do your initial programming. Break it down to its smallest components and build up from there.
Admin
to its parent? WTF
Admin
Actually wrote something like that back in the 90's using ASP. It worked well at preventing script timeouts for request initiated processess that were likely to take a long time on a shared web server.
Admin
thank you ever so much for NOT ANSWERING THE QUESTION! that example shown, has nothing to do with multi-threading.. the emails are still sent synchronously.. what a waste of web space!
Admin
have a look for Multiplatform PHP multithreading engine http://anton.vedeshin.com/articles/lightweight-and-multiplatform-php-multithreading-engine
Admin
LOL I think that stuff can be done with PHP3...
Admin
Well if its you who are calling that page in your browser, then you can call the mailing script through javascript (from javascript code, AJAX or whatnot) In this case there might be a way to see progress, and error messages. The mailing script can also be made to log results somewhere.
Thats not too bad, and has advantages. It does look better from the web hosts perspective then having a php script fork a dozen of children, and is actually easier to code.
Its just that I would never have thought of it hadnt I read it here...
Admin
Those answers are wrong. You can do true multi-threading in PHP. The only limitation is it has to be run in CGI form, not an apache module. Just use the PCNTL functions. http://php.net/pcntl_fork
Admin
useful if you have 100% control over your own web server. don't expect much from shared hosting...
Admin
Question:
Is it possible to return/retrieve a value sent to an IMG tag?
Example:
<? // requester.php echo '<img src=\"http://exius.net/processor.php?id=5\">'; echo "new value: $returned; ?> <? // processor.php $returned = $id++; ?> <!--requester.php outputs-->new value: 10
Admin
found something called cURL. it is not exactly the answer, but it can return values produced by an independent php page, whilst your initiator page will have to wait for a finish before loading the next function.
not ideal for threading. takes me 3 seconds for a simple cURL request, while only 0.02 seconds or less for IMG sendage.
sample: http://forums.digitalpoint.com/showthread.php?t=141762
Admin
How do u post comments on TDWTF??
^^^stupid question
Admin
This can be done using HTTPRL or Guzzle. http://drupal.org/project/httprl/ https://github.com/guzzle/guzzle