1

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/

  • With your current question we can't determine anything other than you have an error, please provide some code. – Bankzilla Apr 21 '15 at 00:19
  • Have a look over this question and see if the answer fixes the issue http://stackoverflow.com/questions/25787376/laravel-modules-system-db-class-not-found – Bankzilla Apr 21 '15 at 02:18
  • Also where are you running the code? that doesn't look like a controller or model – Bankzilla Apr 21 '15 at 02:19
  • @Bankzilla in iron.io its not controller and model –  Apr 21 '15 at 02:45
  • @Bankzilla The API that im integrating http://www.iron.io/ –  Apr 21 '15 at 02:48
  • If you're using them as helper files are they autoloaded? if not you'll have to use the namespace to find the database class. By the looks of the other answer its `use DB` and then reference everything with `\DB:table.....` – Bankzilla Apr 21 '15 at 03:16

2 Answers2

0

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.

Margus Pala
  • 8,433
  • 8
  • 42
  • 52
  • yes i did that yesterday. using this `header("location: mywebsite.com");` but ddnt work –  Apr 22 '15 at 00:24
0

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.

Travis Reeder
  • 38,611
  • 12
  • 87
  • 87