I have a development server where I log in to (through ssh). Apple automatically creates the AppleDouble files/directories, which doesn't work well with Symfony. Every time I want to use a command (mostly doctrine:schema:update). I get AppleDouble errors about classes that don't exist.
Is there any way to tell Symfony to ignore those AppleDouble files?
I saw this issue on GitHub, but it's closed in favor of other issues, but I don't really know how to implement it.
(https://github.com/symfony/symfony/issues/5877)
Try to disable this in OSX itself:
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
Found on this thread.
The folder is created not by Apple but by NAS which you are using probably. Look at this FAQ
So if you use Netatalk you should probably look at its docs. Same folders are created by RedyNAS. But the common pattern as I understood is to run command from terminal that #Valentas described. And then remove the folders recursively.
If you have to hold folders and make Symfony work you should modify the value of Finder::vcsPatterns. As the property is static you can add the following code to the app/console (or bin/console):
...
Finder::addVCSPattern('.AppleDouble');
$kernel = new AppKernel($env, $debug);
...
Related
My existing Laravel project is such that all the tasks are executed sequentially. I have identified part of the code which can be run in parallel using PHP threads and can reduce the response time.
Instead of using pthreads, there was suggestion given that why not use appserver.io - which is fully multithreaded php server itself. One can use its MessageQueue feature, add all your job to this queue, and it will automatically fork worker threads. You don't have to manage anything.
I have already deployed existing Laravel app on appserver.io (copied project under /opt/appserver/webapps/ folder) but now I don't know how to use appserver's MessageQueue. My project uses psr-4, where as appserver is psr-0. Laravel has it's own DI and so does appserver.
All I want to do is, use appserver's MessageQueue to get more workers executing one function in parallel. I'm new to appserver and not sure how the directory structure should look like or what configuration I have do it. Any pointers will be helpful.
you can connect and send to the MessageQueue from within your Laravel application. First you've to install the client library appserver-io/messaging by adding "appserver-io/messaging" : "~1.0" to your composer.json. Then you can send a message with
$queue = MessageQueue::createQueue('pms/myQueue');
$connection = QueueConnectionFactory::createQueueConnection('my-laravel-app');
$session = $connection->createQueueSession();
$sender = $session->createSender($queue);
$sender->send(new StringMessage('Some String'));
assuming you've an application named my-laravel-app, that resides in the folder /opt/appserver/webapps/my-laravel-app and a MessageQueue called pms/myQueue, defined in a file META-INF/message-queues.xml. The file would look like
<?xml version="1.0" encoding="UTF-8"?>
<message-queues xmlns="http://www.appserver.io/appserver">
<message-queue type="MyReceiverClass">
<destination>pms/myQueue</destination>
</message-queue>
</message-queues>
In that example, the receiver class MyReceiverClass has to be available under /opt/appserver/webapps/my-laravel-app/META-INF/classes/MyLaravelApp/Receivers/MyReceiverClass for example.
A good start is the example application that comes with simple MessageQueue example running some simple import functionality.
I'm about to start writing a Symfony2 application and I've come across some notes I must have written a while back about ensuring I write Symfony2 controllers with the fact it needs to be ran from the command line too.
Rather than bash out a load of controllers and seemingly be happy they work in a web browser, I want to ensure all controllers work on the command line too.
A lot of them will need to be ran from the command line, e.g. Cron Tasks etc.
(1) My notes tell me to insert this in AppKernel.php:
* This prevents a 'You cannot create a service ("request") of an inactive scope ("request")' error
<?php
class AppKernel extends Kernel
{
protected function initializeContainer() {
parent::initializeContainer();
if (PHP_SAPI == 'cli') {
$this->getContainer()->enterScope('request');
$this->getContainer()->set('request', new \Symfony\Component\HttpFoundation\Request(), 'request');
}
}
}
?>
(2) I've also got a pre-written request listener that runs various code on every request, and I'm aware the variables generated won't be used on the command line.
(3) I know that none of my Apache config will run (as it's not running inside Apache), and I also know that there's two php.ini files (CLI and Apache).
What else do I need to consider?
What else isn't available on the command line compared to a browser?
I would consider Console Component.
Symfony 2 has a build in interface for creating CLI based commands that will have the entire application bootstrapped, it's called Console Component.
Build out your cronjobs and tasks using this and you can use dependency injection to ensure you have all of the services you need.
I'm sure with some research you could figure out how to load a controller if necessary--controller forwarding or virtual?
I have attempted to create a cron job in my CakePHP 2.x application. But all of the resources I have read online seem to be either doing it completely different to one another with little consistency or explain it in very complex terminology.
Basically I have created the following file MyShell.php in /app/Console/Command
<?php
class MyShell extends Shell {
public function sendEmail() {
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail();
$email->from('cameron#driz.co.uk');
$email->to('cameron#driz.co.uk');
$email->subject('Test Email from Cron');
$result = $email->send('Hello from Cron');
}
}
?>
And I want to say run this code at midnight every night.
What do I do next? As the next part really confuses me! I have read on the Book at: http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html that I should run some code in the terminal to make it do it at a certain time etc. And I can set these up using my hosting provider rather easily it seems.
But I'm rather confused about the Console directory. What should go in what folder in here: https://github.com/cakephp/cakephp/tree/master/app/Console
/Console/Command
/Console/Command/Tasks
/Console/Templates
Also noticed that many of the files are .php (e.g. my Shell file is also .php), but according to documentation I've read for Cron jobs, the executed files should be .sh?
Can anyone shed more light on this?
And what would the code be to call that command?
e.g. would presume this is incorrect: 0 0 * * * cd /domains/driz.co.uk/html/App && cake/Console MyShell sendEmail
Thanks
No. There is no way to do it just in PHP. But that doesn't matter, because crons are easy to set up.
In that article you linked to, you still have to set up a cron - the difference is just that you set up a single cron, that runs all your other crons - as opposed to setting up one cron per job. So, either way, you have to learn to create a cron.
The instructions depend on your server's operating system and also what host you're with. Some hosts will have a way to set up cron jobs through a GUI interface like cPanel or something, without you having to touch the terminal.
It's usually pretty easy to find instructions online for how to set up cron jobs with your host or server OS, but if you're having trouble, update your question with your host's name, and your server OS and version.
Also ---------------------------------
Often in cron jobs you'll be running a shell script (.sh). But don't worry about that for this case; your's will end in .php.
Re: the directory structure:
/Console/Command is where your new file should go.
If you're doing a lot of shell stuff, you may want to abstract common code out into the /Console/Command/Task folder. Read more about that here. This probably won't be needed in your case.
/Console/Command/Templates is where you can put custom templates for the Cake bake console - don't worry about that for now.
If I've only got a couple of cron jobs to run, then I create just one file called CronJobsShell.php, and put them all in there.
Really, you should read Cake's documentation on shells from start to end. It will give you a nice picture of how it all hangs together.
This can be done very easily by the following steps -:
1) Create a shell let's say HelloShell.php in Console/Command
<?php
class HelloShell extends AppShell
{
public function main()
{
//Your functionality here...
}
}
?>
This shell can be called by Console/cake hello
2) Write the command crontab-e .This will open up the default editor or the editor which you select Now as we want that our shell should run after at midnight write:-
0 0 * * * /PATH TO APP/Console/cake hello
For better understanding refer https://www.youtube.com/watch?v=ljgvo2jM234
Thanks!
I have netbeans setup with xdebug so it can debug php. However, this only works if I create a php project. It will not work if I try opening a stand alone php file. So my question is, is it possible to debug a stand alone php file which is not part of a netbeans php project?
If that is not possible, how do I debug stand alone php files with netbeans?
No, There is none that I am aware of. As Myrddin mentioned the debugger needs some configurations that is a part of netbeans project.
but the best way you can debug a single file is to copy it on a project folder, and click the debug project, once the debug session is set then you can browse the PHP File that you want to debug and it will actually go through xdebug.
Good Luck!
Each project can have it's own configuration (you can have 1 project that has PHP5.4 interpreter, one the is PHP5.6, one that is a command line and another that is a web project), but if you configure a general PHP 5 Interpreter:
If you work on a windows machine you can use this code (filename is php.cmd)
set XDEBUG_CONFIG="idekey=netbeans-xdebug"
#php.exe %*
If you want to be able to debug, your interpreter should have the XDEBUG_CONFIG system variable and make sure it's connected to netbeans. You should set this to the same value in your Debbugging section of the PHP's config:
Next thing - if you right click inside the editor you will have the Debug File option, and a prompt window will pop:
You don't really need anything here. Just hit the "OK" button.
As you can see, this final result is debug session of the t1.php file within c:\TEMP\ (which is not a working project):
Short answer: CTRL + SHIFT + F5
You can find the answer here:
https://blogs.oracle.com/netbeansphp/entry/run_file_without_project
I'm not entirely sure, but I think it is not possible, because you need some configuration to get the debugging working, and this configuration is part of a project.
You can always use print_r and var_dump to debug a single file. But that is probably not the answer you're looking for.
xdebug is very heavy and old tool you can use Kint php debuger here.
its free, so you can download Here
it's pretty replacement for var_dump(), print_r() and debug_backtrace().
you need to add kint.class.php file using include or require function.
require '/kint/Kint.class.php';
that's it.
and you can use like
########## DUMP VARIABLE ###########################
Kint::dump($GLOBALS, $_SERVER); // pass any number of parameters
// or simply use d() as a shorthand:
d($_SERVER);
########## DEBUG BACKTRACE #########################
Kint::trace();
more help is available on https://github.com/raveren/kint/
Good Luck :)
I have been trying to get my php to be able to create sql procedure files. My page does everything just as it needs to. It even writes to file correctly, but now I need it to add the file to svn and then also commit. I have been trying
system("svn commit", $trash);
but I cannot seem to get it to work. I have been able to get
system("svn add ".$fileName);
to work and i get common "A................fileName added" or what ever it says. I think that when I try to commit the file svn is waiting for authentication or something, I think this because I don't get anything back in the $trash...
All help is appreciated, thanks.
There is a PECL extension for working with SVN:
svn_commit — Sends changes from the local working copy to the repository
Example from Manual:
svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, 'Bob');
svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, 'abc123');
var_dump(svn_commit('Log message of Bob\'s commit', array(realpath('calculator'))));
There is also a PEAR package:
http://pear.php.net/package/VersionControl_SVN
VersionControl_SVN is a simple OO-style interface for Subversion, the free/open-source version control system. VersionControl_SVN can be used to manage trees of source code, text files, image files -- just about any collection of files.
You can go with a full svn commit command line like :
svn commit --username USER --password PASS
Further options available at : http://svnbook.red-bean.com/en/1.1/re06.html