The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 20, 2019, 11:01:23 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: hit webpage, from PHP, without waiting around for answer  (Read 3334 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: December 10, 2009, 12:07:19 PM »

How do i do that?
Im sure its just me being an idiot, but I cannot figure it out.

I have a php webpage.
It gets hit randomly by users, just like any other normal webpage.
When it runs, I want it to hit another webpage behind the scenes, but not wait around for an answer.
file_get_contents no worky for this.

What does?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #1 on: December 10, 2009, 01:00:37 PM »

You can fork, or fire off a brand new thread from the CLI. PHP doesn't support even pseudo-multithreading like Ruby or Python.
Logged

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: December 10, 2009, 01:08:29 PM »

Write a tiny shell script that does a WGET and exec it with > /dev/null &

or

use my webrequest class, but modify it so that the minute you see any header or anything, it returns as done

or (if the page you want to hit is more complicated/problematic than my class can handle)

This is rather complicated, but it works:
use the webrequest method above to fire off ANOTHER web request that actually does the pull. In other words, thread A makes a call to the local box with webrequest. As soon as it sees header info it quits. The script that is called, is what actually does the pull.

None of the streaming mechanisms (fget/open file_get etc) will abandon early. You'll have to go socket level if you want to do it directly.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: December 10, 2009, 04:41:56 PM »

ive tried the fsock loop until you see something then bail method, but it doesnt actually seem to work?
Im gonna try that again. i don't want to do a shell script, since it splits code, and I hate that.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #4 on: December 10, 2009, 04:50:42 PM »

ah ... if the website doesn't send enough to push the header, then you won't get a signal to bail.

This is why I actually did method 3, described above. The intermediate process send back (immediately) about 4K of space and did a flush, which was enough for Apache to dispatch the header... then I could bail. Forgot that piece. Waiting on other websites never worked for me, now that I think of it LOL sorry ... so it's either the intermediate dispatcher or shell script & IMO.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
serialnoob
Journeyman
***
Offline Offline

Posts: 88


View Profile
« Reply #5 on: December 10, 2009, 09:42:05 PM »

Is there a particular reason why none of you suggest ajaxing in this case ?
Logged

Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #6 on: December 10, 2009, 10:10:59 PM »

this would be from PHP serverside, not the client, so AJAX is not quite viable.
Its actually related to an ajax delio though.

I have an ajax that hits a webservice, but the webservice needs to generate the result first, which can take a few seconds. So I tell the ajax to piss off over and over until its done.
However i am suffering RACE conditions because of some details that are way too hard to go into.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #7 on: December 16, 2009, 08:37:30 AM »

it has to be a some kind of CLI thing

or recently ive been playing around with the __destruct magic method which is only called at object destruction which if you dont explicitly destroy, is done at the very last minute so the user doesnt really notice and pressing stop doesnt seem to cause any problems...

in my case, im serializing the object like this (its ripped out of somewhere so wont work as it stands but you get the idea)


class selfSerializingOnDestruct{

    
//use object caching?
    
public $useObjectCaching=true;
    
//public $useObjectCaching=false;
    
private $objectCacheDays=7//how many days to cache for

    
public function __destruct() {
        if(!
$this->useObjectCaching) {return false;}
        
$this->store();
    }

    public function 
getByID($forceUpdate=false$useCaching=true) {
        if(!
$this->id) {
            if(
$this->debug) {
                die(
'ID not set, please set ID before querying for data');
            }
            return 
false;
        }
        if(
$useCaching) {
            if(
$wake=$this->wake()) {
                return 
$wake->ID;
            }
        }
        if(
$forceUpdate || ($this->ID==='not set')) {
            
/** snipped - just intialise the data properly rather that wake up**/
        
}
        return 
$this->ID;
    }

    public function 
store() {
        
$this->getEverything();
        
$clone = clone $this;
        
$clone->dbh=null;
        
$clone->useObjectCaching=false;
        
$clone->isClone=true;
        if(
$this->dbQuery("select id from objects where id = ?", array($this->id))->fetch()){
            
$this->dbQuery("update objects set object = ? where id = ?", array(serialize($clone), $this->id));
        }else{
            
$this->dbQuery("insert  into objects set object = ?, mpn = ?, last_refresh = NOW()", array(serialize($clone), $this->mpn));
        }
        unset(
$clone);
    }

    public function 
wake() {
        if(!
$this->useObjectCaching) {return false;}        
        if(
is_array($this->woken)) {
            if(
array_key_exists($this->id$this->woken)) {
                return 
false;
            }
        }        
        
$obj=$this->dbQuery("select object, last_refresh from objects where id=?", array($this->id))->fetch();
        if(
$obj) {
            
$refreshLimit time() - ($this->objectCacheDays * (24*60*60));
            if(
$obj->last_refresh $refreshLimit){
                
$this->dbQuery("delete from objects where id=?", array($this->id));
                return 
false;
            }
            
$wake unserialize($obj->object);
            if(!
is_object($wake)) {return false;}
            
$reflect = new ReflectionObject($this);
            foreach(
$reflect->getProperties() as $p) {
                
$this->{$p->name} = $wake->{$p->name};
            }
            
$wake->useObjectCaching=false;
            
$wake->isWake=true;
            
$wake=null;
            
$reflect=null;
            
$this->woken[$this->mpn]=true;
            
$this->useObjectCaching=true;
            
$this->getEverything(); //anything not already in the object will be initialised
            
return $this;
        }
        return 
false;
    }
}
Logged
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #8 on: December 16, 2009, 12:18:56 PM »

interesting.
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #9 on: December 16, 2009, 12:28:49 PM »

What if you made a table that contained actual classes and another
table with metadata about what values to call the classes with
and then make a CRON job to wake up every5 seconds, do a query to check
the 'things to do list'... then it could take some actual php code,
execute it, and store the results by its unique id in some other
sort of message table..  then you could fire off a request to
requestawebpage.php.. it would dump the request into the things
to do table ... the cron would wake up and get its tasklist from the table,
do the task and report the task to the results datatable or whatever...

then you could just loop until the result table was populated?

Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!