?
Solved

Multiple "threaded" processes?

Posted on 2003-11-19
2
Medium Priority
?
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

771 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