SEO

 idiot

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?  Applause

perkiset

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

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

m0nkeymafia

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

perkiset

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

SEO

 idiot

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  :-

webprofessor

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.

perkiset

<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>

webprofessor

quote author=perkiset link=topic=264.msg3040#msg3040 date=1188493266

<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

mac

 hines 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.


perkiset

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...

webprofessor

quote author=perkiset link=topic=264.msg3047#msg3047 date=1188510422

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

webprofessor

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..

perkiset

Applause blocking  Applause Applause Applause

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   Applause 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>

perkiset

quote author=webprofessor link=topic=264.msg3053#msg3053 date=1188513863

http://www.

php

 

.net

 /manual/en/ref.sockets.

php

 #19141


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.

webprofessor

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

perkiset

Fair enough, humbly and knowledgeably posted as well.

Thanks again,
/p


Perkiset's Place Home   Politics @ Perkiset's