How can I call a shell from my component.
Here is my shell
<?php
class PrintShell extends AppShell {
function main()
{
App::import(‘Component’, ‘BusinessLogic’);
$businessLogic = & new BusinessLogicComponent();
$businessLogic->initialize();
$settings = $businessLogic->senReminderEmail();
// senReminderEmail Mail function is defined in my Controller/Components/BusinessLogicComponent.php File
}
}
?>
I dont want it to call using commands.
How can I do this.Any help
Does this makes sense?
you want to call shell
i think, do you want to use cron job in cakephp..?
mostly appshell used to work with cron job and i have also faced out this one and i had not used appshell i set up my cron job from godaddy server and putted all files in webroot folder which may operate during cron time so i just verified..dear..
Related
I like to test (Feature test via phpunit) some methods in the Job Class (Lumen Queue) to make sure it is working correctly.
Problem is Job Class have some jobs methods like $this->job->getJobId() and $this->release(5);
If I run phpunit from console, I get an error:
Error: Call to a member function getJobId() on null
The test code look like this:
/**
* #test
*/
public function it_has_successfully_uploaded()
{
$job = new SomeJob(['file' => ['file1.zip']]);
$job->handle();
}
How do I solve this issue?
Your code is using $this->job->getJobId(), but nowhere is that property declared or set. Are you perhaps using the InteractsWithQueue trait but forgot to include that in your code paste?
If so, the job property is set in InteractsWithQueue::setJob. This method may be called from several places, but in your case it is probably from Illuminate\Queue\CallQueuedHandler::setJobInstanceIfNecessary. This is some internal initialization of your job that Laravel does for you, which you must imitate in your test setup.
I would implement a simplistic version of Illuminate\Contracts\Queue\Job and call $job->setJob(new SimplisticVersionShazaamJob(...)); before calling $job->handle().
In code igniter web application we can can the controller and methods like domain-name/controller/method_name.Is there any way to access core PHP class methods like the same way?
How can i access the method in browser like domain/car/hello
The Car.php file is in the server root xampp/htdocs/Car.php
My class file Car.php:-
class Car{
public function hello()
{
echo 'Hello';
}
}
Please help.
You don't. The browser talks to the server (to PHP) using HTTP. HTTP has absolutely no notion of functions, or even what a programming language is. PHP also has no mechanism to allow anything to directly access/call a function from outside. The only thing that happens is that the web server decides based on the requested URL which PHP script to execute. That's all. Execution will always start on the first line of the script being executed, not directly in a function somewhere.
You can/have to write code which inspects the requested URL or otherwise decides which function to call, and then call it in PHP code.
Php is a server-side programming language, you simply cannot execute it in your browser without HTTP Server.
Upd: if you mean how can you run it in xaamp then you should run it. Run this by calling file like simple url page, for example localhost/Car.php
Try something like this:
<?php
Car $car = new Car();
$car->hello();
class Car{
public function hello(){
echo 'Hello';
}
}
I have my own library class which is designed for gathering data from external web sites (uses curl). This class has constructor which receives parameters (e.g. URL, xpaths) and method updateDatabase. How to pass parameters to constructor and call method updadeDatabase in app internally? This method should be fired e.g. two times per day without user request (using the cron) So I don't want insert this code in controller and create appropriate route. How to do this?
class Source
{
public function __construct(Http $http, array $params)
{
...
}
public function updateDatabase()
{
...
}
}
Your best bet is probably to create an artisan command. This gives you access to to run your code within the Laravel framework from the command line (or cron job).
All the information you need for creating an artisan command can be found here.
Basically, inside the command's fire() method you would do something like:
public function fire() {
$source = App::make('Source'); // or however you instantiate your class
$source->updateDatabase();
// output a message to the command line
$this->info('All done.');
}
Your command can also take arguments and options from the command line, if you need to pass those in.
The documentation linked above will tell you all you need to know.
I am trying to set up a cron job using COdeigniter but I cannot figure out how to get it to work. I have a file called email_check.php in my controllers folder, and I have added a .cron file to the servers cron folder, which contains the following
email_check.cron
*/1 * * * * php /var/www/html/application/controllers/email_check
email_check.php
class Email_check extends CI_Controller {
function __construct()
{
parent::__construct();
$this->index();
}
function index()
{
$this->load->model('admin/info_model');
$this->info_model->addTestData();
}
}
The addTestData adds a new row into a database table. I would like this to run every minute, however it isn't working at all and I have no idea why.
Maybe it may be the paths that are wrong. Do I need to point the php part to the php.exe in the server.
If anyone could help or point me in the right direction it would be greatly appreciated!
To use CodeIgniter via the commmand line, you need to call the index.php file and pass in the controller and method as arguments, plus any other arguments. So at the minimum the cron job call would be:
~/public_html/sitefolder/index.php controller method
Or using the path to your application index file. But, you also need to use PHP compiled for the command line, not just PHP for CGI-FCGI. So your call might be something like:
/ramdisk/bin/php5-cli ~/public_html/sitefolder/index.php controller method
Depending on where your PHP CLI is located.
This won't work because just hitting your email_check.php controller won't do anything because its not going to call your index() method.
You want to either write a script that is going to create a new instance of the controller and call the method or call it via a URL, something like this I think
* * * * * wget http://sitename.com/email_check
I am trying to use php-resque to queue and execute ffmpeg conversions on my server. I understand broadly how it should work, but I am having some trouble with the details and can not find any tutorials. Specifically, I don't understand where I should place my job classes, and how to give the classes to my workers and start my workers. The read me only says "Getting your application underway also includes telling the worker your job classes, by means of either an autoloader or including them."
Hopefully someone can outline the overall structure of using php-resque.
You can put your job classes where you want. It'll depend on your application structure.
How to create a job class
For example, let's suppose the class VideoConversion, used for the ffmpeg conversion.
class VideoConversion {
public function perform() {
// The code for video conversion here
}
}
In your main application, before using php-resque, let's say you have something like that
public function uploadVideo() {
// Upload and move the video to a temp folder
// Convert the video
}
And you want to enqueue the 'convert video' part. Let's just queue it to the convert queue:
public function uploadVideo() {
// Upload and move the video to a temp folder
// Let's suppose you need to convert a 'source video' to a 'destination video'
Resque::enqueue('convert', 'VideoConversion', array('origine-video.avi', 'destination-video.avi'));
}
When queuing the job, we passed the path to the source and destination video to the VideoConversion class. You can pass other argument, it'll depend on how your VideoConversion class is written.
A worker will then poll the convert queue, and execute the VideoConversion job. What the worker will do is to instantiate the VideoConversion class, and execute the perform() method.
The job arguments (array('origine-video.avi', 'destination-video.avi')), third argument when queueing the job with Resque::enqueue, will be available inside the perform() method via $this->args.
# VideoConversion.php
class VideoConversion
{
public function perform() {
// $this->args == array('origine-video.avi', 'destination-video.avi');
// Convert the video
}
Find your job classes
The VideoConversion class can be put anywhere, but you have to tell your workers where to find it.
There's multiple ways to do that
Put you jobs classes in the include_path
In your .htaccess or the apache config, add the directory containing all your job classes to the include path. Your workers will automatically find them.
Main issue with this method is that all your jobs classes must be in the same folder, and that all your job classes are available everywhere.
Tell each worker where to find your job classes
When starting the worker, use the APP_INCLUDE argument to point to the job classes 'autoloader'.
APP_INCLUDE=/path/to/autoloader.php QUEUE=convert php resque.php
The above command will start a new worker, polling the queue named convert.
We're also passing the file /path/to/autoloader.php to the worker. (see here to learn to start a worker)
Technically, the worker will include that file with include '/path/to/autoloader.php';.
You can then tell the workers how to find your job classes:
Use basic include
In the '/path/to/autoloader.php':
include /path/to/VideoConversion.php
include /path/to/anotherClass.php
...
Use an autoloader
Use php autoloader to load your job classes.
Use set_include_path()
set_include_path('path/to/job');
That way, your jobs are in the include_path just for this worker.
Closing thought
APP_INCLUDE is binded to the worker you're starting. If you're starting another worker, use APP_INCLUDE again. You can use a different file for each worker.
You can also design your job classes to execute more than one job. There's a tutorial explaining how to do that. It covers from the basic of a queue system to how to use and implement it.
If it's still not enough, take a look at resque documentation. php-resque API is exactly the same. Only difference is that Resque job classes are written in Ruby, whereas php-resque's one are in php.
Hi Please check out following tutorial on how to use resque with phalcon.
http://www.mehuldoshi.in/background-jobs-phalcon-resque/