February 12, 2013
No Comments
I have recently been running some MySql scripts that wrote to a file.
These worked fine locally, but as soon as I deployed them I started to get the error above.
After much looking around I came across this solution.
When I was developing locally, I was connecting with a user that had global privileges. When I was running the code on the server I was connecting with a user that only had privileges for the database I was using.
The issue is that then FILE privilege is a Global setting, so the user did not have access to it, hence the access denied message.
Grant FILE privileges and you can connect as expected
November 21, 2012
No Comments
I am currently putting together an automated system that converts user input within Magento.
As this runs using cron, I will be unable to see if anything goes wrong, unless the errors are logged.
Now it is possible to set custom error and exception handlers that will log most things, but I needed to cover all bases and try to log in the event of a fatal error.
It is possible to do this by calling register_shutdown_function and checking for an error there – see here for a full explanation on how to do this.
The problem I had was that this would not work within Magento. After a lot of going through the code it appears that if you have developer mode set to true, then your function will not be called. Once it is disabled the function works as expected.
November 14, 2012
2 Comments
Recently the good folks at chrome have added a feature where you can reload without the cache, which is in a right-click on the reload button, but I was really confused as some machines seem to have it and others don’t.
The key is whether developer tools is open or not! If you’re using a recent version of chrome, press F12 to open the developer tools and then you can right-click the reload button, and you get three options – Reload, Hard Reload (redownloads images) and Empty Cache and Hard Reload.
September 7, 2012
No Comments
Having a stack trace is very handy at times but wouldn’t it be nice if you could click on the filename in the stack trace in your browser and your IDE take you to the file and line that it’s talking about?
Well, with PhpStorm and kint, you can! Using a plugin called Remote Call, the PhpStorm IDE can listen on a port and go to files and line numbers via an ajax call.
To configure this, grab the latest version of kint, and copy it’s sample config to an actual config file, and edit the section about pathDisplayCallback to look like this :-
$_kintSettings['pathDisplayCallback'] = "_kintLine";
function _kintLine( $file, $line = NULL ) {
if ( !$line ) { // means this is called from resource type dump
return $file;
}
return "<u><a class=\"kint-ide-link\" href=\"http://localhost:8091/?message={$file}:{$line}\">" . $file . "</a></u> line <i>{$line}</i>";
}
You can even be clever with regex to make the filenames be relative – for instance, we run our projects from a directory below one called, oddly enough “projects” and our function looks like this :-
function _kintLine( $file, $line = NULL )
{
$shortname = preg_replace('#.*/[Pp]rojects/[^/]*/#','',$file);
if ( !$line ) { // means this is called from resource type dump
return $shortname;
}
return "<u><a class=\"kint-ide-link\" href=\"http://localhost:8091/?message={$file}:{$line}\">" . $shortname . "</a></u> line <i>{$line}</i>";
}
Now, if you call Kint::trace(); from your file that you’ve included Kint.class.php from, you get a clickable stacktrace!
August 16, 2012
No Comments
When you are monitoring a log file you may want to narrow it down, and format the results. This simple one line command will break up the output from a log file to make it easier to quickly read
tail -f /path/to/log | grep "search term" | sed 's/\(.*\)/----------\n\1\n----------/'
March 27, 2012
No Comments
If you have a staging copy of your site anywhere then you might not bother copying over your entire catalogue of product images etc.
You might decide to drop in absolute URLs for those images so that they are pulled from live. However you really don’t want absolute URLs in your code and you certainly don’t want that to go live because it just adds unnecessary bloat.
A nice trick you can do here is make a change to your staging site as follows. Of course ensure this change doesn’t go live, but it should be just one file so that’s easy to handle.
(Note this assumes you already have jQuery available on your page)
<script type="text/javascript">
$().ready(function(){
$('img').each(function(){
var src = $(this).attr('src')+'';
if(-1 == src.indexOf('http')){
var new_src = 'http://www.LIVEDOMAIN.co.uk/'+src;
$(this).attr('src', new_src);
}
});
});
</script>
Don’t forget to change LIVEDOMAIN to be your real live domain
javascript, By:
admin
No Comments
Tags:
abolute,
debugging,
development,
hosting,
image,
images,
img,
javascript,
jquery,
staging,
tip,
urls
February 25, 2012
No Comments
These two Magento functions looks more like there is no obvious difference between them, but there is.
addAttributeToFilter(‘some_attribute1′,’attribute_value’) filters a Magento entity collection (e.g Products, categories) by only selecting entities that has ‘some_attribute’ equal to ‘attribute_value’ while
addAttributeToSelect(‘some_attribute2′) tells Magento to return add ‘some_attributes’ to the set of properties that would be returned for a collection of entities.
A combination of these two functions could be likened to
SELECT 'some_attribute2' FROM Table WHERE 'some_attribute1'='attribute_value'
December 12, 2011
No Comments
The php simpleXML object is my preferred way of working with XML, but it has some unusual quirks that can drive you up the wall. One of these is that, by default, it will not read CDATA within an XML file, and will just leave the node blank.
If you need to access this data then create your xml object like this
$xmlFile = "/path/to/xml/file.xml";
if (file_exists($xmlFile)) {
$xml = simplexml_load_file($xmlFile,'SimpleXMLElement', LIBXML_NOCDATA);
echo $xml-cDataNode;
}
November 14, 2011
No Comments
One of the things that can catch you out if you have a paranoid server admin is that various magento extensions will contact external servers (such as SagePay or Mailchimp).
If the server admin has blocked outbound web traffic (to avoid DDoS attacks and other malicious traffic), these extensions will slow you down at every step.
Simple answer, if you’re running magento, ensure you have outbound traffic enabled. Also, don’t assume that just because you can use lynx, apt-get et al at the command prompt that you can as the web server user. IPTables and pf both have checks for outbound user, so be sure to test as www-user or apache.
October 14, 2011
No Comments
If you use Netbeans along with Xdebug to facilitate step through debugging when coding PHP then you may come across this issue.
It’s possible to get it into a semi working scenario where you can have working breakpoints and see variable values but you have no idea which bit of code you are actually stepped up to.
This can happen if your server path and project path are not correctly configured.
To resolve this simply go to your project properties, run configuration and then hit the advanced button.
The server path should be the absolute path to the project root on the server (eg /home/server/sites/blah/) and the project path should be the path on your local machine to the project files (eg /home/joseph/projects/blah/).
Stop any debugging sessions and then start another one up and if you have the paths set right, you should get the behaviour you expect where Netbeans highlights the current line of code and allows you to step through the code to figure out what’s going on.
php, By:
admin
No Comments
Tags:
debugging,
local,
netbeans,
path,
php,
problem,
project,
remote,
server,
solution,
xdebug