简体   繁体   中英

Iron.io seems to be not detecting my database

I tried to run my hello_worker.php but it doesn't seem to be detecting the database. I'm using Laravel 4.

This is my code in Iron.io:

<?php
// Worker code can be anything you want.
// echo "Hello!";
// print_r(getPayload());

// Simulating hard work for 5 seconds...
// sleep(5);

DB::table('test')->insert( array('content' => 'every one minute') );
// When you're ready press 'Run code ...'

This is the error that i received in my email.

Message: Occurred during run: PHP Fatal error: Class 'DB' not found in /mnt/task/hello_worker.php on line 9

The API that im integrating http://www.iron.io/

I have been using iron.io just for the message queue. I ask iron.io to call specific URL in my Laravel app and process the request in the Laravel app not in the remote iron.io server.

To run code on IronWorker, you must include all your dependencies along with your worker. Whichever dependency has the DB class, you must include that. Here's an example worker with dependencies:

https://github.com/iron-io/dockerworker/blob/master/php/

You can use Laravel's database module / ORM (called Eloquent ORM ) outside of a Laravel app, here's some info on how to do that:

http://www.edzynda.com/use-laravels-eloquent-orm-outside-of-laravel/

Another option is to use Push Queues, which uses IronMQ to deliver messages to an endpoint on your application:

http://laravel.com/docs/5.0/queues#push-queues

Here's a video showing this in action:

https://vimeo.com/64703617

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM