?
Solved

Multiple "threaded" processes?

Posted on 2003-11-19
2
Medium Priority
?
301 Views
Last Modified: 2006-11-17
Hi,
Is it possible to run 10 or 20 functions at the same time in php?. In windows development we would create threads, is this a feature of php or am I barking up the wrong tree? lol

I basically have a function (or 2 ) I call that returns parsed html and depending on which page it is looking at it can take some time. So, what I want to do is say, OK I need to parse these 20 pages lets parse all 20 at the same time and wait until all 20 processes have finished then publish, post or process the overall results.

Any help appreciated.
S
0
Comment
Question by:08718712060
2 Comments
 
LVL 6

Accepted Solution

by:
aolXFT earned 1500 total points
ID: 9783824
Check out http://www.php.net/manual/en/ref.pcntl.php , to see if you can find an answer to your question there.

PHP AFAIK cannot support multiple threads, and they don't recommend using multiple processes in a web server enviornment.

I think you'll just have to find a faster way to work.

Can we see the code you are currently using?
0
 

Author Comment

by:08718712060
ID: 9783986
Hi aolXFT,
Its the same code you provided to me last night!!! re search engine parsing. I have split it up as a test script but basically it would be great if I could parse all 15 or so search engines at once. ie the Do_Google and Do_Alltheweb etc

<?php

$words            = "key words to search for";
$my_url            = "domainnametofind.com";
$html            = "";
$loc_tag            = "";

$page = $page. page_header();

do_google();
do_alltheweb();
//List other 15 or so


$page = $page.page_footer();

echo $page;
exit;


/*============================================================================*/
function page_header()
{
global $words, $my_url;
$tmp = '<table width="52%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000033">
  <tr>
    <td align="center">
      <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#CCCCFF">
        <tr>
          <td> <p><font color="#FF9933" size="2" face="Verdana, Arial, Helvetica, sans-serif">..::</font><font color="#000033" size="2" face="Verdana, Arial, Helvetica, sans-serif">Keywords
              Searched<font color="#FF9933">::..</font></font></p></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFCC"><font color="#999999" size="2" face="Verdana, Arial, Helvetica, sans-serif">'.$words.'</font></td>
        </tr>
      </table>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#CCCCFF">
        <tr>
          <td> <p><font color="#FF9933" size="2" face="Verdana, Arial, Helvetica, sans-serif">..::</font><font color="#000033" size="2" face="Verdana, Arial, Helvetica, sans-serif">Domain
              to locate<font color="#FF9933">::..</font></font></p></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFCC"><font color="#999999" size="2" face="Verdana, Arial, Helvetica, sans-serif">'.$my_url.'</font></td>
        </tr>
      </table>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#CCCCFF">';
return $tmp;
}
/*============================================================================*/

/*============================================================================*/
function page_footer()
{
$tmp = '</table></td></tr></table>';
return $tmp;
}
/*============================================================================*/


/*============================================================================*/
function do_google()
{
global $html, $words, $my_url, $loc_tag, $se_domain;
$html = file_get_contents('http://www.google.com/search?num=100&hl=en&ie=UTF-8&oe=UTF-8&q=' . urlencode($words));
$loc_tag = '<p class=g>';
$se_domain = "www.google.com";
print_listing();
return 1;
}
/*============================================================================*/

/*============================================================================*/
function do_alltheweb()
{
global $html, $words, $my_url, $loc_tag, $se_domain;
$html = file_get_contents('http://www.alltheweb.com/search?_sb_lang=pref&cs=utf-8&cat=web&q='. urlencode($words) .'&avkw=fogg');
$loc_tag = '<!--IS--><p class="result"';
$se_domain = "www.alltheweb.com";
print_listing();
return 1;
}
/*============================================================================*/



/*============================================================================*/
function print_listing()
{
global $html, $words, $my_url, $loc_tag, $page, $se_domain;


if(strpos($html, $my_url) !== false){
    list($above, $below) = explode($my_url, $html, 2);
    $pos = substr_count($above, $loc_tag);
} else {
    $pos = 0;
}

if ($pos == 0)
 {
 $page = $page. '<tr>
    <td width="50%"><p><font color="#FF9933" size="2" face="Verdana, Arial, Helvetica, sans-serif">..::</font><font color="#000033" size="2" face="Verdana, Arial, Helvetica, sans-serif">'.$se_domain.'<font color="#FF9933">::..</font></font></p></td>
    <td width="50%"><font color="#660000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Not Ranked</font></td>
  </tr>';

 } else
 {
 $page = $page. '<tr>
    <td width="50%"><p><font color="#FF9933" size="2" face="Verdana, Arial, Helvetica, sans-serif">..::</font><font color="#000033" size="2" face="Verdana, Arial, Helvetica, sans-serif">'.$se_domain.'<font color="#FF9933">::..</font></font></p></td>
    <td width="50%"><font color="#003333" size="2" face="Verdana, Arial, Helvetica, sans-serif">Ranked at position
      : '.$pos.'</font></td>
  </tr>';
 }

return 1;
}
/*============================================================================*/


?>
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question