PHP - Php Forking Replacing 'threads' When They End
Hi
I wonder if anyone will be kind enough to help. I am getting into forking with pcntl_fork() I intend to create a script that runs 24/7 running 100 forks/children/'threads' simultaneously. Once a child has finished it's task and exited how can I start a new child to replace it? I need some kind of infinite loop that can continually check for exited children and set up new ones. I'm finding it hard to get my head round since I'm new to forking. Can anyone suggest a way to do this? Thanks in advance. Similar TutorialsI have a site that executes a shell script that takes a bit of time to run, the information it outputs does need to be displayed in the page. My problem is whenever the script is run, it stalls the entire apache process until the script has run. So every time the script gets run, I'm looking at about 30 - 120 seconds of downtime while that happens. I'd like to fork off the process if possible so that apache can continue to operate, and I think I'm just having issues understanding where I would place and implement the code. A user fills out a form and hits submit, so should I have the form action submit it to a new page with the forking function to process the shell script/etc? And if so, how do I get it to return the results, because doesn't that then mean that the web page would technically just display the page from the form submission, and not the actual script results? For clarification, I'm referring to using the pcntl_fork function, and I did look at it on php.net, I think I'm just a little confused still as how to apply it to my scenario. Looks like if the output wasn't necessary it wouldn't be quite so hard. Hi I am presently writing a code which does the following steps given a site 1) get some keywords (written a function for it) 2) search google for these keywords (I have used curl and getURL functions for these) 3) perform keyword search in the first page of googles results. Presently I have used curl and curl_multi_getcontent but when i run the code it consumes 100% of my server. My server will not respond in this case if someone else pings. I have been trying to do pcntl_fork, but could you let me know how to optimize this code by threading and forking. I am a newbe in PHP please let me know the structure of how to invoke multiple threads and process the same. If you have someother suggestions please let me know that too. I have been searching Google on PHP Threads, I am getting mixed thoughts. Is Multi Threading in PHP Possible? Some say no, some say yes and some say you need to make a workaround. What is the real answer? Please help. I am trying to replace parenthesises () in a string with <>. I tried preg_replace and str_replace, but was not success. Here is what I have for str_replace: $word = "(test)"; $word = str_replace('(', '<', $word); $word = str_replace(array('(', ')'), array('<','>'), $word); hi freaks, still working on my email bot. im currently trying to escape <>-tags to be displayed- but not the browser wont exectute it (i.e. xls-tags) i want them as chars. so whin my $content is like <xsl:stylesheet> <xsl:template match="/"> <more xls...> it shows a stylesheet. i just want the chars. Here is what ive been trying so far: but its bad Code: [Select] <?php $string='<tag> > < asdasf'; $bomb=array( '<', '>', ); $defusal=array( '-', '!', ); $string= preg_replace($bomb,$defusal,$string); echo $string; ?> error: Warning: preg_replace() [function.preg-replace]: No ending matching delimiter '>' found in C:\xampp1\htdocs\code.php on line 13 donno any further now How come this is not replacing correctly? $rp = strtr($rp,"[TIMES]","<span style='font-family: Times New Roman, Times, serif'>") Hey guys, I have a quick question. Im going to be making a script that will output the name of a news article along with the poster's name beside it. There is only a certain amount of space where that stuff can go so I want to know how I can make it so that say after 20 characters, it ends and puts "..." beside it. Is this possible with php? How would I do it? Hey all, i need a function or a way to replace each letter in a string to a star (*) Thanks Hello, Is str_replace the best way to go about this? In MYSQL, a html template is stored, such that: Quote <table width="{$width}">lots of other ........</table> This is extract from the database, and stored in a string. I would use eval(), but, any user can update this template, so I need to be able to set which variables will be replaced with what the variable is. Thanks! Hi Guys, I use this function to generate seo friendly names for my products once pulled from the database: function generate_seo_friendly_links($pNM, $pID) { $replacedNM = str_replace(" ", "-", $pNM); $replacedNM = rtrim($replacedNM); $brandNewSEOFriendlyURL = "<a href='$replacedNM-$pID.html'>$pNM</a>"; return $brandNewSEOFriendlyURL; } This works great, the only thing is say a product is stored in the database like: product name it would then be converted to: product-name.html if for example theres 2 spaces: product name it would then be converted to: product--name.html with the 2 "--" so for every space it finds we replace with a "-" etc is there a way i could ignore more than 1 space and always have it like product-name-here.html so the names are more uniformed, i can't think of a way to do it. any help would be appreciated thanks guys Graham //$x = ereg_replace('[-a-z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*','<a href=\'mailto:\\0\' '.$style.'>\\0</a>',$x); hi, i have an article with several paragraphs. However i would like the first paragraph to be converted into a header. string replacement will not work as it will replace all the p tags. i just want the 1st set of p tags to be replaced. can anyone help? thanks Hi, I have 2 arrays, named $old_teams1 and $old_teams2. The arrays have from 6 values upwards. If $old_teams1 looks like this: Code: [Select] Array ( [0] => 3 [1] => 4 [2] => 3 [3] => 4 [4] => 1 [5] => 2 ) and $old_teams2 is the has the same mixture of values from 1-4..... .. How do I create a loop that will change all values of $old_teams1 and $old_teams2 to new values such as, 1->3, 2->4, 3->1, 4->2.... (The new values have been randomly generated). I want to be able to replace, let's say, every fifth letter from a string. The string is unknown, though, it could come from database, or a POST form. So I'm unsure if I could use str_replace. I think I may need to use preg_replace(), but I'm not not sure. Hello, I have been trying to replace a variable's value inside a function in case it matches a certain criteria but I can't seem to get it right. Let me give an example: Code: [Select] <?php function replace_value($obj) { if($obj==1) { $obj=2; } } $number = 1; replace_value($number); echo $number; So how do I go about making $number = 2, because it still has a value of 1 even after I pas it through the function replace_value. Ok mixing javascript with php.... im having bugs . I basically want to replace any broken image links with a picture "noimage.gif" in the images folder. I tried this code but am getting the error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/showroom.php on line 78 This is the javascript header - all seems fine: <script language="JavaScript" type="text/javascript"> function ImgError(source){ source.src = "/images/noimage.gif"; source.onerror = ""; return true; } </script> this is the code thats erroring... is it the way ive written in the code into the IMG tag? while($row = mysql_fetch_array($result)){ echo "<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=100% BORDER=0>"; echo "<TR />"; echo "<TD WIDTH=30% VALIGN=TOP />"; echo " <A HREF='images/".$row['photo']."' target=_blank><IMG SRC='images/".$row['photo']."' width=186 height=155 border=0 onerror="ImgError(this);" /></A> "; echo "<br />"; echo "</TD>"; echo "<TD WIDTH=10 VALIGN=TOP />"; How can I replace ' and " with str_replace? When I using the following code, I will get error. $string = str_replace(""", "something", $string); I have phrases in a string with the structure of "Note: some description" I want to replace "Note with (, but how can I replace the second " with )? Hi first post here and very new to php. I built a form so that a data entry perosn can "build" new pages for our companies website. I pretty much have the basics of the form and the action page coded correctly, however my issue is that I need this final page where the form inputs are posted too to be an html document. I read some about the str_replace() function, but I'm not understanding how I could use that to replace the file extension of a page. Maybe I'm going about this all wrong. I also read that one can edit the htaccess folder to allow an html file to run php script. Not sure which way would be the best. One thing to mention though, is this application would be run locally to our back up files which is then scheduled to be uploaded to the remote server very night. Any help or suggestions would be greatly appreciated. |