Solved

Multiple "threaded" processes?

Posted on 2003-11-19
2
239 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 500 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now