Solved

Multiple "threaded" processes?

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

18 Experts available now in Live!

Get 1:1 Help Now