Solved

Multiple "threaded" processes?

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
if (is_singular not working 5 39
MySQL limit and not so limited 13 40
Unwanted output from my query 5 41
assigning javascript variable to php variable 8 42
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.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
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.

749 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