The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 22, 2019, 07:44:27 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Stupid question i know... but i am an idiot  (Read 5148 times)
SEOidiot
Journeyman
***
Offline Offline

Posts: 84


^ Hes a pint sized Ned Flanders


View Profile
« on: May 24, 2007, 03:42:03 PM »

Anyone who knows me knows i occasionally ask retarded questions but hey....

Currently im scheduling my php scripts for stats etc via a cron job, no problem with that but is there any other way? Just curious?  D'oh!
Logged

<mango>Yummmmmmmmmmmmm</mango>
<pie>ewwwwwwwwwww</pie>
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: May 24, 2007, 04:10:55 PM »

First, you are, of course, an idiot.  ROFLMAO

More importantly, I don't know of a more efficient way off hand, except to tell Gertrude to do it for you on a regular schedule. She's a dear and I don't think she'd mind.

/p
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.
m0nkeymafia
Expert
****
Offline Offline

Posts: 240


Check it!


View Profile
« Reply #2 on: May 25, 2007, 12:35:00 AM »

Only real other way is to have a list of times and stuff to do stored in a db, then query it on every page load a user does
but its a really bad way of doing it lol
Logged

I am Tyler Durden
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: May 25, 2007, 11:24:02 AM »

MM is hinting there is the polled method, ie., have a separate table of things to do and CRON once a minute to see if there is anything to do... but unless your calendar is way outside the capabilities of the CRON scheduling syntax, then this is pretty redundant. If, for example, you want to drop events into a table sporadically that fire sporadically or at unstructured/random times, this might make sense - like a tickler list of contacts... but other than that though, prolly more work than worth IMO.

/p
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.
SEOidiot
Journeyman
***
Offline Offline

Posts: 84


^ Hes a pint sized Ned Flanders


View Profile
« Reply #4 on: May 25, 2007, 01:47:25 PM »

okey dokey - just thought id ask in case there was a way i didnt know that may assist in some areas where cron isnt an option.... no its my site really it is honest  Undecided
Logged

<mango>Yummmmmmmmmmmmm</mango>
<pie>ewwwwwwwwwww</pie>
webprofessor
Rookie
**
Offline Offline

Posts: 15


View Profile
« Reply #5 on: August 30, 2007, 09:55:46 AM »

If you have pcntl compiled in your php can write what ever it is your doing as a daemon. As an example the crawlers for keywordcurious.com's are all controlled by a daemon written in PHP. If you go that route you have to remember to write a start/kill script place it in your rc.d/init.d firectory and add links to them in the proper runlevel directories.  The other option is to add a line to the rc.local file.
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #6 on: August 30, 2007, 10:01:06 AM »

<slight hijack>
WP would you please talk for just a moment about about writing daemons in PHP - QQS:
* is this really a viable thing to do?
* is it all piped comms, sempahores, busy waiting etc or is there an event driven way of doing things?

All my current daemons were written in Kylix and C++ - but I have a lot of new things to do and would like to use PHP if possible.

TIA
</slight hijack>
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.
webprofessor
Rookie
**
Offline Offline

Posts: 15


View Profile
« Reply #7 on: August 30, 2007, 10:31:09 AM »

<slight hijack>
WP would you please talk for just a moment about about writing daemons in PHP - QQS:
* is this really a viable thing to do?
* is it all piped comms, sempahores, busy waiting etc or is there an event driven way of doing things?

All my current daemons were written in Kylix and C++ - but I have a lot of new things to do and would like to use PHP if possible.

TIA
</slight hijack>

Is it viable?
Yes I do it for quite a few things. The real problem was writing the basic daemon correctly to prevent it from forking bombing, making sure it handled all its kids correctly, and making it respond to semaphores ( ie kill -9 ).

is it all piped comms, sempahores, busy waiting etc or is there an event driven way of doing things?

I rarely deal with IPC this way, its a pain. Its usually easier to just give every process its own database connection and pass data that way. The other option I prefer is using sockets for IPC. Both of those are relatively expensive in terms of resources but its never been a problem for the machines I run them on. Generally I am aiming for productivity and self documenting code when I program. If efficient use of resources becomes an issue then its easy to go back solve that if I wrote a solid set of functions and objects.


Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #8 on: August 30, 2007, 02:47:02 PM »

Thank you - but I'm confused just a bit because I haven't seen it done: how, in php, would you bind to a port and sleep until you get pinged? I'm assuming that your daemons are either busy-waiting or you've got a way of sleeping until you are needed...
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.
webprofessor
Rookie
**
Offline Offline

Posts: 15


View Profile
« Reply #9 on: August 30, 2007, 03:36:33 PM »

Thank you - but I'm confused just a bit because I haven't seen it done: how, in php, would you bind to a port and sleep until you get pinged? I'm assuming that your daemons are either busy-waiting or you've got a way of sleeping until you are needed...

fsockopen opens sockets in blocking mode.. meaning when you read from it if theres nothing to read it just waits. Once theres something to read you fork and have the child handle the request.

http://www.php.net/fsockopen
Logged

No links in signatures please
webprofessor
Rookie
**
Offline Offline

Posts: 15


View Profile
« Reply #10 on: August 30, 2007, 03:44:23 PM »

This guy has an example:
http://www.php.net/manual/en/ref.sockets.php#19141

I haven't tested that example but it look good..
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #11 on: August 30, 2007, 03:47:26 PM »

 Idea... blocking  D'oh! D'oh! D'oh!

One last, then I'll leave you be - other than things that I do myself, are there any known leakages to watch out for when coding this way? Is the garbage collection as good as the Zend site says? From the dox, provided I don't write my own PHP funcs and do out-of-band mallocs, I should be all memory managed and not have a care in the world   ROFLMAO I'm just wondering if you have any contrary experience there...

and with that, off to do some testing.
Cheers mate

<edit>Minor Typo</edit>
« Last Edit: August 30, 2007, 03:52:35 PM by perkiset » 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.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #12 on: August 30, 2007, 03:51:42 PM »


Just posted that in the code repository because it's a great resource to have here.
Thanks for that, gonna use it as a base for testing.
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.
webprofessor
Rookie
**
Offline Offline

Posts: 15


View Profile
« Reply #13 on: August 30, 2007, 04:03:35 PM »

I've never had any problems that weren't caused by me.
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #14 on: August 30, 2007, 04:24:23 PM »

Fair enough, humbly and knowledgeably posted as well.

Thanks again,
/p
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.
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!