Build worker queue with codeigniter - codeigniter

I'm, trying to make a worker using this repo and redis
https://github.com/yidas/codeigniter-queue-worker
but i don't find any complete tutorial how to use it. I've tried to use it manual but no luck and keep throwing error, i don't know how to completely build the worker.
if there's any of you have tried or using it, please help to build worker with this lib.
I need to grab around 1 million or more data and build a new database from that data, and i think can't be done by just using 1 single call query, that's why i'm trying to grab all data by using worker so those data can be grabbed consistently without any error.
TRY CASE
I'm trying to load the lib with "use"
<?php if(!defined('BASEPATH')) exit ('No direct script access allowed!');
use vendor\yidas\queue\sec\Controller' as WorkerController;
class User_register_unverified extends WorkerController{
function __construct(){
parent::__construct();
}
function index(){
echo 'Test';
}
}
I Got this Error
An uncaught Exception was encountered
Type: ParseError
Message: syntax error, unexpected '' as WorkerController;' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'
Filename: /var/www/html/lists/services/application/controllers/User_register_unverified.php
Line Number: 9
Backtrace:
File: /var/www/html/lists/services/index.php
Line: 320
Function: require_once
I Try to move the lib to "libraries" codeigniter directory and use require_once and i change the class name to "Worker"
<?php if(!defined('BASEPATH')) exit ('No direct script access allowed!');
// use vendor\yidas\queue\sec\Controller' as WorkerController;
require_once APPATH.'libraries/Worker' as WorkerController;
class User_register_unverified extends WorkerController{
function __construct(){
parent::__construct();
}
function index(){
echo 'Test';
}
}
Also get same error
An uncaught Exception was encountered
Type: ParseError
Message: syntax error, unexpected 'as' (T_AS)
Filename: /var/www/html/lists/services/application/controllers/User_register_unverified.php
Line Number: 4
Backtrace:
File: /var/www/html/lists/services/index.php
Line: 320
Function: require_once
Then i tried to use as lib
<?php if(!defined('BASEPATH')) exit ('No direct script access allowed!');
// use vendor\yidas\queue\sec\Controller' as WorkerController;
// require_once APPATH.'libraries/Worker' as WorkerController;
class User_register_unverified extends CI_Controller{
function __construct(){
parent::__construct();
$this->worker = $this->load->library('worker');
}
function index(){
echo 'Test';
}
}
and i got this notif
An Error Was Encountered
Non-existent class: Worker
I noticed that i did wrong type directory in "use" way and repaired it
<?php if(!defined('BASEPATH')) exit ('No direct script access allowed!');
use vendor\yidas\queue\src\Controller as WorkerController;
class User_register_unverified extends WorkerController{
function __construct(){
parent::__construct();
// $this->worker = $this->load->library('worker');
}
function index(){
echo 'Test';
}
}
Yet, still get the same error
Fatal error: Class 'vendor\yidas\queue\src\Controller' not found in /var/www/html/lists/services/application/controllers/User_register_unverified.php on line 6
A PHP Error was encountered
Severity: Error
Message: Class 'vendor\yidas\queue\src\Controller' not found
Filename: controllers/User_register_unverified.php
Line Number: 6
Backtrace:

You can use like this
<?php
use yidas\queue\worker\Controller as WorkerController;
class Job extends WorkerController {

Use require 'vendor/autoload.php';.
<?php
//use yidas\queue\worker\Controller as WorkerController;
require 'vendor/autoload.php';
class Job extends WorkerController {

Related

Type error: ReflectionFunction::__construct() expects parameter 1 to be string, array given

I am new to Laravel. I am getting this Type Error when I change the following routings as below mentioned way.
My previous routing is as below.
web.php
Route::get('/add-teams',[
'as'=>'teams.add',
'uses'=>'TeamsController#addTeams'
]);
It works fine.
But I need to change that as this.
<?php
use App\Http\Controllers\TeamsController;
Route::get('/add-teams', [TeamsController::class, 'addTeams'])->name("teams.add");
Then this error appears. "Type error: ReflectionFunction::__construct() expects parameter 1 to be string, array given"
Please help me to solve this.
TeamsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Teams;
class TeamsController extends Controller
{
public function saveTeams(Request $request){
$team=new Teams();
$team->team_name=$request->team_name;
$team->description=$request->description;
$team->save();
return back()->with('team_added','Team added successfuly!');
}
}

Undefined Variable Request in Laravel 5

I am having issues it says Request is undefined same goes for DB.
public function edit(Request $request,$id) {
$name = $request->input('stud_name');
DB::update('update student set name = ? where id = ?',[$name,$id]);
echo "Record updated successfully.<br/>";
echo 'Click Here to go back.';
}
Looks like you're missing use statements that tell your script where to find these. Add
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
in your file after namespace ...

Getting Error in CodeIgniter RESTful API

defined('BASEPATH') OR exit('No direct script access allowed');
require('application/libraries/REST_Controller.php');
use Restserver\Libraries\REST_Controller;
class demo extends REST_Controller {
function __construct(){
parent::__construct();
}
public function demo1_get()
{
echo 'demo 1';
}
}
Error Image
enter image description here
This is My REST_Controller
enter image description here
Hi, I m getting Error for making Codeigniter RESTful API. Please Help me to solve this problem.
It should be like this :
Make sure you have REST_Controller.php in your libraries folder
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '/libraries/REST_Controller.php';
class Demo extends REST_Controller
{
function __construct(){
parent::__construct();
}
public function demo1_get()
{
echo 'demo 1';
}
}
You need to follow the link https://itsolutionstuff.com/post/codeigniter-3-restful-api-tutorialexample.html
and then after you run the code you will get a small error Unable to load the requested language file: language/english/rest_controller_lang.php
The problem is that codeigniter can't find the rest_controller translations. You just need to create this file /application/languages/english/rest_controller_lang.php
Then copy & paste this code inside:
<?php
/*
* English language
*/
$lang['text_rest_invalid_api_key'] = 'Invalid API key %s'; // %s is the REST API key
$lang['text_rest_invalid_credentials'] = 'Invalid credentials';
$lang['text_rest_ip_denied'] = 'IP denied';
$lang['text_rest_ip_unauthorized'] = 'IP unauthorized';
$lang['text_rest_unauthorized'] = 'Unauthorized';
$lang['text_rest_ajax_only'] = 'Only AJAX requests are allowed';
$lang['text_rest_api_key_unauthorized'] = 'This API key does not have access to the requested controller';
$lang['text_rest_api_key_permissions'] = 'This API key does not have enough permissions';
$lang['text_rest_api_key_time_limit'] = 'This API key has reached the time limit for this method';
$lang['text_rest_ip_address_time_limit'] = 'This IP Address has reached the time limit for this method';
$lang['text_rest_unknown_method'] = 'Unknown method';
$lang['text_rest_unsupported'] = 'Unsupported protocol';
Hope this helps

CodeIgniter Passing POST data from RestClient to RestServer API("SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data")

I've spent my whole day trying to figure out this problem. Posting this issue here is my last hope. I hope someone can help to continue working on my first job.
SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data
So, POST works fine when directly passing data from my views to the RestServer directly. However, RESTServer API is not able to find POSTs data sent from the RestClient.
my Example
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . 'libraries/REST_Controller.php';
class Example extends REST_Controller {
function __construct()
{
parent::__construct();
$this->methods['get']['limit'] = 500;
$this->methods['post']['limit'] = 200;
$this->methods['delete']['limit'] = 50;
}
public function post()
{
$message = array(
'id' => null,
'name' => $this->input->post('name'),
'message' => $this->input->post('email')
);
$this->set_response($message);
}
}
First off:, try renaming your POST function from post() to index_post() that is simply a standard that can help with SOLID principles.
Second:
Is there in your Controller somewhere whare you put the use CI_Controller namespace either you added it in the REST_Controller.php file, since it is not in the Example controller; just REMOVE that namespace. The below 3 requirements should work just fine for you.
require(APPPATH . 'libraries/REST_Controller.php');
use Restserver\Libraries\REST_Controller;
require (APPPATH . 'libraries/Format.php');
class Example extends REST_Controller {
...
}

Codeigniter extend Blueimp Upload library

I have blueimp file upload working well with codeigniter. I use the UploadHandler library as is. But I want to extend it to replace two functions that create the unique filename. The code for this is in the BlueImp Github wiki.
I created an extended library thus:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_UploadHandler extends UploadHandler {
public function __construct() {
parent::__construct();
$CI =& get_instance();
$CI->load->library('UploadHandler');
}
protected function upcount_name_callback($matches) {
$index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
$ext = isset($matches[2]) ? $matches[2] : '';
return '-'.$index.''.$ext;
}
protected function upcount_name($name) {
return preg_replace_callback(
'/(?:(?:-([\d]+))?(\.[^.]+))?$/',
array($this, 'upcount_name_callback'),
$name,
1
);
}
}
When I try to run it, I get an 'unable to load UploadHandler' error. If I remove my MY extension, the original code runs. What is wrong with my extension code? Isn't this the proper way to extend CI libraries?
And, yes, the filename for my file is MY_UploadHandler.php
Thanks!
I noodled over this for a while and finally figured it out. To extend a custom library, you need to 'require once' the file it is extending, prior to the definition of the class.
EX:
require_once("UploadHandler.php");
class MY_UploadHandler extends UploadHandler
{
}
Hopefully that helps.

Resources