chrisboulton / php-resque

PHP port of resque (Workers and Queueing)
MIT License
3.43k stars 759 forks source link

DB access in perform() #335

Open wqsaali opened 7 years ago

wqsaali commented 7 years ago

Hey from me and @rabnawazPikesSoft

How i can access database in perform() method of Job class in codeignitor? I have implemented it and it is working but i want to do some sort of updation in perform() method. Is there any way to do this?

danhunsaker commented 7 years ago

I haven't used CodeIgniter since late version 2.x, so I don't know how it works now. When I was using it, though, I had a CLI-only route set up that would set up the environment variables and include(FCPATH . '/vendor/bin/resque'), thus ensuring I had access to the framework from within my jobs, since the framework had started the worker(s). (You can also use the APP_INCLUDE environment variable to include() any file you like to do this, but that doesn't seem to work as well for this.)

One thing to keep in mind is that each job is run in a forked process, so you'll need to reconnect to your DB manually when the job starts (or, more accurately, sometime between job start and the first DB interaction). The same goes for pretty much any other PHP resource-type value.