Menu

Hack for "call to undefined functi...

Help
2013-03-05
2013-10-24
  • Nobody/Anonymous

    hey there,

    if you're working on a windows 8 machine and receiving this error:
    "Fatal error: Call to undefined function sem_get() in  /libs/ProcessCommunication/PHPCrwalerProcessCommunication.class.php on line 92"

    change the following code:

    {
          $sem_key = sem_get($this->crawler_uniqid);
          sem_acquire($sem_key);
        }
    

    into

     if (!function_exists('sem_get')) {
                    function sem_get($key) {
                        return fopen(__FILE__ . '.sem.' . $key, 'w+');
                    }
                    function sem_acquire($sem_id) {
                        return flock($sem_id, LOCK_EX);
                    }
                    function sem_release($sem_id) {
                        return flock($sem_id, LOCK_UN);
                    }
                }
              
                $sem_key = sem_get($this->crawler_uniqid);
                sem_acquire($sem_key);
    

    For the developers of this fantastic Framework, i got this error by using the following code:

    $crawler = new MyCrawler();
    $url = "www.php.net";
    $crawler->setURL($url);
    $crawler->addContentTypeReceiveRule("#text/html#");
    $crawler->addURLFilterRule("#\.(jpg|jpeg|gif|png)$# i"); // ignore pictures
    $crawler->enableCookieHandling(true);
    $crawler->setPageLimit(5);
    $crawler->enableResumption();
    $crawler_id_filepath = "mycrawlerid_for_" . $url . ".tmp";
    if (!file_exists($crawler_id_filepath)) {
        $crawler_ID = $crawler->getCrawlerId();
        file_put_contents($crawler_id_filepath, $crawler_ID);
    }
    else {
        $crawler_ID = file_get_contents($crawler_id_filepath);
        $crawler->resume($crawler_ID);
    }
    $crawler->go();
    unlink($crawler_id_filepath);
    
     
  • Uwe Hunfeld

    Uwe Hunfeld - 2013-03-05

    Hi!

    Thanks a lot for your report and the workaround-fix!

    Right now i don't even know why sem_get is needed/used when using process-resumption, maybe this
    is just an unecessary call somewhere within phpcrawl, will have to take a deeper look.

    I openeed a bugreport for this topic:
    https://sourceforge.net/tracker/?func=detail&aid=3606951&group_id=89439&atid=590146

    Again, thanks!

     
  • Anonymous

    Anonymous - 2013-10-24

    i even had this error on a unix machine , for both the file above and PHPCrawler.class.php.

    applying the fix above worked.

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.