cakephp: running controller action as a cron job not working - cakephp

Am trying to run a controller action as a cron job, but it is giving me the message, "could not open input file"
To do the above, i used this link, http://bakery.cakephp.org/articles/view/calling-controller-actions-from-cron-and-the-command-line....
But not working for me, I also tried to place the cron dispatcher in /app/webroot, but still not working for me.
thanks...

PHP cannot load your cron_dispatcher.php. Make sure your cron entry is correct, i.e. points to the correct full path of your PHP file. Also make sure that you have your access rights correctly. It's possible that the file exists but that when PHP runs under cron, it is not allowed to read the file.
PS: Have you considered using CakePHP's Shell functionality instead of this dispatcher? It was designed for CLI use.

Call direct your action
wget http://www.example.com/homes/my
in my action wirte your code
set in cpanel ....

Related

when does dispatch.xml get updated?

I understand that the dispatch.xml that resides in the default service WEB-INF/ is the one that the appengine pays attention to. However, when I do an appengine:update (java, mvn) the routing rules don't seem to update. I actually have to do a separate appengine:update_dispatch to effect the changes. Do I misunderstand something or am doing something incorrectly? Thanks.
I'd say it's an understanding problem. You appear to be expecting a single operation. It's not.
Updating the default service app code and updating the dispatch rules (an app-level config affecting all app services) are distinct, independently executable operations, mapped as such in mvn.
From Uploading the dispatch file:
To upload the dispatch file, use the appcfg update_dispatch
command, and specify the war directory for the default service. Be
sure that all the services mentioned in the file have already been
uploaded before using this command. # cd to the war directory
containing the default service appcfg.sh update_dispatch .
You can also upload the dispatch file at the same time you upload one
or more services, by adding the optional auto_update_dispatch flag,
which can be used in two forms:
appcfg.sh --auto_update_dispatch update <app-directory>|<files...>
appcfg.sh -D update <app-directory>|<files...>
I guess it's possible to create a single mapping as well, under the hood using that --auto_update_dispatch flag, but IMHO it'd be even more confusing and you'd still need to remember 2 separate cmds (I wouldn't like to potentially affect other running services by a dispatch update when I'm uploading a particular service).

How to execute a Shell method in a Controller?

I am using a cakephp3 plugin to manage a mail queue to send newsletter (Lorenzo Cakephp Email Queue). It works fine, but I need to use a Shell method with the bake command to send the newsletter.
It is not a problem with a cron job, but I would like to be able to send test mail without waiting for the cron job.
I tried to call the bake command with a php exec command, but it does not work (maybe a right problem ?) but I don't have access to the server to manage the rights. But, as the method and the controller are both in cakephp, I think it's weird to do it with a console (external) bake call...
Is there a way to call a Shell method from a Controller, which would be the "cleanest" and easiest way ?
Thanks all for you help !
which would be the "cleanest" and easiest way ?
A shell should be considered similar to a controller - controllers don't call controllers.
Consider putting the cli logic in a common place and have the cli and controller action call that, not each other. The relevant cli code is a few lines of code, but it's not actually doing anything complex, just looping on the emails to be sent, and sending them one by one.
I need to use a Shell method with the bake command to send the newsletter
Note that bake is a cli, it is not "the" cli, and forms no part of the runtime usage of that plugin.
bin/cake EmailQueue.sender -h
It may not work currently, because you're using the wrong cli commands to try and run it from your controller action - though it's not a very good idea/design to do it that way anyway.

File is not creating on heroku using cakephp

I tried to make a file on heroku using PHP code:
$fh = fopen("../DownloadFiles/".$filename,'a');
fwrite($fh,$s);
but the file has not been created and it is not showing any error. Please help.
This should work just fine, but are you aware that if you're running multiple dynos, that file will exist only on the dyno that served that one request, and not on all the others?
Also, Dynos restart every 24 hours, and their state is reset every time you push a change to Heroku, so you cannot store persistent information on them; that's called an ephemeral filesystem.
You could, for instance, store uploaded files on Amazon S3, like described in the docs: https://devcenter.heroku.com/articles/s3-upload-php
Two remarks about your original issue:
you're probably running an old version of CakePHP which mangles all internal PHP error handling and writes it out to a log file (if you're lucky), so you can't see anything in heroku logs, and it's not possible to configure it otherwise; upgrade to a more recent version that lets you log to streams and then use php://stderr as the destination
in general, if you want to write to a file in PHP, you can just do file_put_contents($filename, $contents)...
Does the DownloadFiles folder exist in the deployment? Node fs gives error if the directory is not found. You can add a snippet to check if dir exists and if not then create. You can use fs.exists and fs.mkdir.
For more info http://nodejs.org/api/fs.html

Resarting AppEngine after a file is modified

Whenever I make a change to my html file, I have to resart appengine server to see the change reflected. Why is this so? In Flask for example the server automatically reloads whenever it detects a file change. Can this be done in AppEngine?
That's not the normal behavior for local development. You should be able to update your html files, as your code, without the need to restart the server.
Can you tell us more about your setup? Might there be a caching mechanism in your code that doesn't check the filesystem to refresh appropriately?

How can I script WordPress for non-GUI automated Pages/Posts-import?

This is probably a "cannot see the forest because of the trees" situation,
but how do I create a script which does the automated import of Posts/Pages, without a hook in the WP Website-GUI (e.g. in Theme's functions.php). It should be standalone triggerable by calling the script name via webserver.
via this API-call wp_insert_post()
You want to use the WordPress API (http://codex.wordpress.org/XML-RPC_wp) to connect. You can do this with almost any scripting language, but since you mention running it on the webserver, and WordPress is written in PHP, we'll go with that language for now.
Check out this tutorial:
http://life.mysiteonline.org/archives/161-Automatic-Post-Creation-with-Wordpress,-PHP,-and-XML-RPC.html
He shows example of how to create a script that will insert a post into your WordPress blog. The script can be given execute permissions and ran via the command line or a cron job.
You will have to code the logic to get the post from wherever your data is stored, though.

Resources