Hi Tom,
Thanks for your reply. The only issue with doing it that way is that
I'm not in a polling loop and PHP doesn't have threads. As a pseudo
example, it works something like this:
while(next_fam_event()) { <-- blocks until next event is available.
processEvent();
doDatabaseStuff();
}
The issue is that the next_fam_event call blocks indefinitely. If PHP
had threads, I could easily just keep a connection alive in the
background, but alas, it doesn't. My other option (of course) is to
switch to a polling method, but that wastes CPU and database
resources. This is a fairly common pattern which I've used countless
times in other languages... Also, async JMS messaging generally works
something like this, only you specify callbacks to handle events and
so on. I just can't find a way to make it work with Symfony. But
thanks so much for responding!
Best,
JLS
On Feb 4, 2009, at 4:24 PM, Tom Haskins-Vaughan wrote:
>
> I've just come across a similar situation. I need to download some
> very
> large files and write to a log at the beginning and end of the
> download.
> I did the following:
>
>
> Start db manager;
>
> Start download using ftp_nb_get()
>
> in while loop
> {
> access the database periodically to ensure regular connections
> (I simply update a last_access_at field)
> }
>
> finish download and write to log.
>
> Not sure if I've explained myself, so gimme a shout if you want
> clarification.
>
> Tom
>
> John L. Singleton wrote:
>> Speaking of answering questions.... :) I actually have a question
>> that's
>> been bugging me and I haven't been able to get a good answer on
>> either
>> the forums or the users list.
>>
>> This question pertains to MySQL used with Symfony 1.0 and Propel.
>>
>> I have a LONG running batch script that intermittently needs access
>> to
>> MySQL. I begin the script with the lines:
>>
>> ///code
>>
>> $databaseManager = new sfDatabaseManager();
>>
>> $databaseManager->initialize();
>>
>> code////
>>
>> And the program goes into an event loop, using FAM as the notifier.
>> But,
>> if lots of time elapses between the time I initialize and the time I
>> need the connection, I get an error about MySQL has gone away. This
>> means that the idle timeout was exceeded for MySQL. I know I could
>> just
>> set the timeouts to forever, but that is not a tenable solution.
>>
>> The question is: how to I tell Symfony to reconnect to MySQL? Is the
>> solution to use something like Propel::getConnection() every time I
>> need
>> it? Some other solution? As I mentioned, this script basically runs
>> 24/7, only waking up when it needs to do something. As such, doing
>> something like upping the MySQL timeout isn't really an option for
>> me.
>>
>> I've tried doing stuff like:
>>
>> ///code
>>
>> $databaseManager = new sfDatabaseManager();
>>
>> $databaseManager->initialize();
>>
>>
>> {do some stuff}
>>
>>
>> $databaseManager->shutdown();
>>
>>
>> {wait}
>>
>>
>> $databaseManager = new sfDatabaseManager();
>>
>> $databaseManager->initialize();
>>
>> ///code
>>
>> But that doesn't really work. So I guess the question is, what is the
>> best "Symfony" way to do this? I've looked into just grabbing a
>> connection from the MySQLConnection class, but that seems to break
>> all
>> of the abstraction and sort of defeat the whole purpose of using a
>> framework like Symfony in the first place. Could someone please
>> advise?
>>
>> Best,
>> JLS
>>
>>
>>
>>
>>>
>
> --
> Tom Haskins-Vaughan
> Temple Street Media: Design and Development for the Web
> [email protected] | www.templestreetmedia.com
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---