I'm trying to "faux-fork" a process (an email being sent via SMTP) in my web application, and the application is built on Kohana.
$command = 'test/email';
exec('php index.php '.$command.' > /dev/null/ &', $errors, $response);
I'm getting an error --
Notice: Undefined index: SERVER_NAME
When I look into Kohana's index.php file, I see that it is looking for a variable named SERVER_NAME, but I guess it is coming up NULL because Kohana couldn't detect this value and set it prior to run.
Any ideas how to get Kohana to run via command line?
After looking into Kohana3 source code, I found that it has support for cli (system/classes/kohana/cli.php). You can pass 3 options (uri, method, get, post). So:-
$ php index.php --uri="items/list"
would call the list method in Controller_Items.
As far as I know you can't run the kohana files directly in command line because of its bootstrap methods.
You could do 2 things:
export all command like functions outside kohana and run them independently.
Something else you could do is running it trough the index.php located in the kohana main folder while passing the $controller, $method variables to it so it ends up at the right object where your code is located:
For kohana 2:
php index.php controller/method/var1/var2
Kohana 3
php index.php --uri=controller/method/var1/var2
Edit:
Kohana has a great CLI task runner from version 3.3 onward as official module. For version 3.2 it's still an unofficial module. I suggest you use these because they give a lot of extra options on running from CLI:
Kohana 3.2 - https://github.com/Zeelot/kohana-minion
Kohana 3.3 - https://github.com/kohana/minion
And Kohana2 is just php index.php controller/method/param1/param2/etc
Kohana was built to run on the CLI as well as web.
If you are using Kohana 3 then you can run it from the terminal.
Example
php index.php --uri=controller/action
Options
--uri
--method
--get
--post
For Kohana 3, check out these docs and source.
I had a similar issue
Did you or anyone add the SERVER_NAME to the index.php file?
If so either remove the code outside the index.php (and or bootstrap) OR you can wrap it it in a
if (PHP_SAPI === 'cli')
{
// ...
} else {
//....
}
Related
Recently, I installed lumen (5.0.4) mfw and ran into an issue with page load on default configuration. I have unpredictable behavior of page load process.
Sometimes it loads okay but sometimes instead of loading I am getting a download dialog with zero size unnamed file or it throws an exception like
NotFoundHttpException in Application.php line 1109:
(At first, I want to say that other non lumen/laravel sites work fine) Server configuration:
Apache 2.4.12
PHP 5.6.7-1
Zend Engine v2.6.0 with Zend OPcache v7.0.4-dev
I think the problem is with php working through php-fpm because with fcgi configuration it seems to work well.
I tried NotFoundHttpException with Lumen but that didn't help me.
I have same issue, after hours of research and debug, I fixed the issue.
If you are doing something like this ...
$app->run($httpRequest);
instead do ...
$httpRequest = Illuminate\Http\Request::capture();
$app->run($httpRequest);
Hope this is helpful. Thanks!
Change $app->run(); to $app->run($app['request']); in public/index.php (Lumen 5.2)
Is there an easy to setup Codeigniter REST library which I can use to consume a RESTful service? I tried setting up this library. But could not set up Spark. Tried following steps:
Adding a directory named sparks in the root of your codeigniter directory
Adding a custom Loader Class to application/core/MY_Loader.php.
It gave me another error Cannot find spark path at sparks/curl/1.2.1/. Now I am stuck. Wondering why it is so hard to setup RESTful API in codeigniter.
Update: When I try to run
$this->load->spark('restclient/2.1.0');
// Load the library
$this->load->library('rest');
// Run some setup
$this->rest->initialize(array('server' => 'http://api.twitter.com/'));
// Pull in an array of tweets
$tweets = $this->rest->get('1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=jenksuy&count=2');
$tweetobjects = json_decode($tweets);
foreach ($tweetobjects['results'] as $tweet) {
log_message('info', $tweet['text']);
}
I am getting Error: Call to undefined method CI_Loader::spark()
sparks is not necessary SEE EDIT. use this tutorial to start, the author also wrote the libraries
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
download these two to work with the tutorial:
https://github.com/philsturgeon/codeigniter-restserver
https://github.com/philsturgeon/codeigniter-restclient
also at the end of the tutorial - theres many comments and questions, and the tutorial author has answered many of them
EDIT - whoops forgot you have to change one line. and you will need to DL the CI curl library. OK so in the rest client, in the file Rest.php starting at line 53
/* Not using Sparks? You bloody well should be.
| If you are going to be a stick in the mud then do it the old fashioned way
$this->_ci->load->library('curl');
*/
// Load the cURL spark which this is dependant on
$this->_ci->load->spark('curl/1.2.1');
so change it to load curl library the traditional way and commment out the spark reference
$this->_ci->load->library('curl');
// Load the cURL spark which this is dependant on
// $this->_ci->load->spark('curl/1.2.1');
You can install curl 1.2.1 by running the following command on your application root (not your application folder):
php tools/spark install -v1.2.1 curl
Source
I am getting this error
Parameter Errors:
uri - uri is not a valid option for this task!
but my command looks valid:
php /var/www/public_html/index.php --uri=controller/action
i tried also (direct in this folder)
php index.php --uri=controller/action
php index.php --uri="controller/action"
always this error
greetings
Kohana 3.3 changed the way it handles CLI execution. From 3.3 it uses Minion module and --uri param is dropped in favour of --task, therefore you have to create Tasks (as opposed to Controllers).
More in the docs: http://kohanaframework.org/3.3/guide/minion/tasks
Note that docs have an error, there's no $_defaults any more, there's $_options instead. Have a look into API Docs for more details.
I have placed my own php file in /sites/all/modules/<myfolder> and call it via $.post(<myphppage>) from a static html page (javascript function) also in /sites/all/modules/<myfolder>.
However, the php does not appear to be executing as expected, but is getting called (access logs in Apache HTTPD show it is post'ed to).
If I try to manually request the same php page, I receive this error:
Fatal error: Call to undefined function db_insert() in /full/path/to/sites/modules/<myfolder>/<myphppage> on line x.
The echo statement I have in the php page is outputted properly above this error, and simply uses $_GET['paramname']. (And _POST, changed for testing direct request) to print a few query string parameters for debugging).
Also, when I added a call to watchdog, I receive:
Fatal error: Call to undefined function watchdog() in /full/path/to/sites/modules/<myfolder>/<myphppage> on line x.
Is it not possible to access the PHP page directly? Or is there a Drupal library I need to import? Or am I just plain missing something else with how Drupal works?
You are getting those errors about undefined functions because your PHP file is independent from Drupal and it is not bootstrapping it.
The Drupal way of doing what you are trying to do is to create a module (see Creating Drupal 7.x modules, and Creating Drupal 6.x modules) that defines a URL it handles with hook_menu(); that URL is then used with $.post().
As example of the way of bootstrapping Drupal, see the content of the index.php file that comes with every Drupal installation. (The following code is the one used from Drupal 7.)
/**
* Root directory of Drupal installation.
*/
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
The code changes from Drupal 6 to Drupal 7, but drupal_bootstrap() is defined in both Drupal versions.
The correct way is to create a module, anyway. For a list of reasons why a module should use a PHP file that bootstraps Drupal, see Are there cases where a third-party module would need to use its own file similar to xmlrp.php, cron.php, or authenticate.php?
I'm new to symfony and I am trying to run a simple command on the command line but I get an error message.
When I try to execute the command:
d:\new_xam\xampp\htdocs\sf_sandbox_1_2\sf_sandbox>symfony propel:build-model "
I get the error:
'php.exe' is not recognized as an
internal or external command,operable
program or batch file.
Can anybody help me?
This is a fairly common issue on Windows systems for people new to Symfony and/or PHP. It seems to be an issue with the PHP path. See here: http://forum.symfony-project.org/index.php/m/44895/?srch=php.exe+command#msg_44895
Can you try to use the real path for PHP?
i.e.,
"C:\Program Files\PHP\PHP.exe" symfony propel:build-model
At your Symfony directory.
You should be able to prefix everything with "php".
So instead of symfony propel:build-model you can do php symfony propel:build-model.