Can anyone tell me, how to access an action URL of symfony using terminal in ubuntu?
For Example:
http://mysymfonyproject.com/index.php/users/sendnewsletter
Same way, I want to set up an action class URL as cron job. Is it possible to set up cron jobs in symfony?
For Example:
http://mysymfonyproject.com/index.php/crons/sendnewsletter
I think a Symfony Task is what you should look into. There's a lot of built-in tasks, but you probably should write your own task and then call it from cli using a command:
php symfony yourTaskNamespace:yourTaskName
Then you can add such command as a regular cronjob task.
You can check detailed instruction how to create custom Symfony tasks at Documentation Page
Using tasks is the best solution (as Tomasz Madeyski suggested). Just be aware that the tasks work a bit differently than the web app (e.g. read about using sfContext in tasks)
You can also use curl to access your sf pages directly from CLI:
curl -sS http://mysymfonyproject.com/index.php/crons/sendnewsletter >> mylog.log
The -sS option will make curl silent unless there's an error. You can skip that if you don't need it.
The last part (>> mylog.log) will append the result of the request to the log file (it's best if you specify whole path to the log file)
As for setting the cron job it's fairly easy no matter if you use curl or sf tasks. Have a look around the web for a tutorial on setting the crontab, there's plenty of them out there.
Related
I need to make a tool to Browser test my production system. I have read up all about Laravel Dusk and it seems like a perfect tool. However, I need to run tests automatically via schedule and have a dashboard with the results.
I can easily run the command php artisan dusk from the code using the Scheduler, however, how can I get the results? Is there a better option than simply parsing the Console Output from that command? Ideally I would have a way of getting the status of each test (whether it passed or failed) to be able to log, process and display all that information.
The Dusk documentation hasn't got any more information on running the tests programatically, it only has instructions to run via php artisan dusk.
Has anyone encountered this?
Thank you!
The way I have achieved what I needed is to use the command options for dusk/phpunit.
I used --filter=MyTestClass to single out which test I wanted to run, and --log-junit log.log to log the results for that test, which I then parsed via code as well to fetch the results. This allowed me to build a fully custom dashboard that was able to run each test individually, report the results, send notifications etc.
Not the prettiest solution, but it worked well for what I needed. If anyone encounters better way to achieve that (or just use Dusk in general as a browser/scraper outside phpunit) please do post a comment/answer!
In my php project i should have some background process , but in safe mode , because I'm running it on a shared host.
For example my background process code is in the file bg.php and I want it to be executed , write at finish of another specific script.( or maybe with some delay )
I searched a lot. some suggested libraries like beanstalkd but i think this library is heavy for my simple background process and also doesn't have good doc for PHP. some others said functions like exec() which is not possible in safe mode.
1- Does anyone have a simple solution for this problem?
2- I were also mentioned by cron jobs existing in cpanel which
prepare tasks to be executed on a specific time. can I use this
option to solve my problem in some way?
I noted I want a simple and lightweight solution. any suggestions appreciated deeply.
It's not possible use a PHP file served by a HTTP Server because all proceses will die after the request end.
So cPanel cron is a good option, you don't need to have the cron entry always enable, just setup once the entry and disable it after the script start to run.
Only you'll need add & at the end of your cron command to make it run as background.
I am using MVC framework. Now I want to set up cron such that the URL "http://www.xyz.com/controllera/functiona" should be executed. what should i write in the path section for it.
I got something about "GET" command but it wasnt clear.
Can someone please help me out with it?
As you didn't specify any framework the only way to run this cron is this command
wget --spider 'http://www.xyz.com/controllera/functiona'
I assume you are using an MVC framework as controllera is in the url. If it was Kohana (2.3) framework I would have run it by
/usr/bin/php /path/to/index.php controller/method
Most framework has cli interface to run a controller method. Search for your framework.
See these links for different frameworks.
Zend Framework
Kohana 2 & 3
Codeignier
Yii
I don't understand the "module called cron" part of your question. I believe you are confused, cron is a service on Linux and other Unix systems configured thru crontab.
A crontab(5) entry is defined by a time and date and a command to run.
On Linux and Posix systems, you cannot execute or run an URL. Running something involves the execve(2) system call, which requires an executable file path (and arguments).
Perhaps you want to retrieve some URL using the HTTP protocol. You might use a command-line HTTP client, like wget or curl.
So perhaps the command you want to run in your crontab might be
wget http://www.xyz.com/controllera/functiona
but you could use curl
My guess is that you are confused, and don't understand well enough your question. Consider reading some material.
For example, to retrieve that URL once a day at 3 pm, you would have the following crontab entry:
# run everyday at 3 pm a GET HTTP request
0 15 * * * /usr/bin/wget http://www.xyz.com/controllera/functiona
Use the crontab(1) command to configure your crontab (which may contain several entries, and several variable definitions, so you may have to edit it).
I have a script that uses php and curl to auto logon to a site and perform some actions.
That bit is ok but I now want to send the script to other people so they can use it.
So I can create a batch file that executes the script.
The problem will be the users won't have php instaled on their computer and would probally have to enable curl in the php.ini file too.
To ask the user to perform all these actions would be messy. Is there anyway I could create a basic instalation or something like that, that would package the whole thing toghether?
Thanks for any answers :-)
There's phc -- the open-source PHP compiler.
On another note, are you sure your users will have curl installed? And if not, and you decide to distribute it with your app, will they have all curl's dependencies installed?
Found this googling http://www.bambalam.se/bamcompile/
Maybe it's overdoing things but you can
look into Titanium Desktop
http://www.appcelerator.com/products/titanium-desktop-application-development/
Its Open Source, Cross Plataform and free. It basically lets you create a desktop application with web app technologies ( sort of like Adobe Air), and it has support for php scripts. This will of course mean that you have to create an User Interface with at least a button to run your script.
I am working on a ZF application that needs to run a command line script and then parse the results into something meaningful and return to the user.
I know there are various PHP functions, like exec and system, but I was wondering if there is anything built into Zend Framework that does command line scripting easily.
Even if there isn't a ZF specific function, what is the best function/method to use for running a command line script and then retrieving the results in PHP upon completion of the script.
I would write a Service which uses exec to get what you need. You can add some basic error handling there.
You can start an process under linux with this:
ZendX_Console_Process_Unix
But never tryed it..
We recently needed to do this (we use ZF too), hope this helps: http://www.kintek.com.au/web-design-blog/how-to-run-a-php-script-from-command-line/