Could Computing

Symfony 1.4: Doctrine and SQL Azure

 

To get your SQL Azure DB running with Symony 1.4 and Doctrine 1.2.4 you need to make the following changes:

In databases.yml:

all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn:      odbc:DRIVER={SQL Server Native Client 10.0};Server=SERVER.database.windows.net;Database=DATABASE;Encrypt=yes;
      username: USERNAME@SERVER
      password: PASSWORD

Sadly there appeard some ugly errors, but I could fix them (please don’t ask me how I found the solutions).

The first error appeared trying to build the model:

When using the attribute ATTR_AUTO_ACCESSOR_OVERRIDE you cannot use the field name “defaultculture” because it is reserved by Doctrine. You must cho
ose another field name.

In my case it’s not possible to change the field name because the DB schema is not under my control. To solve this I did the follwing changes:

In symfony/lib/plugins/sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php deactivate the setting ATTR_AUTO_ACCESSOR_OVERRIDE:

$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, false);

And in symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Import/Mssql.php I had to change:

    public function listTableColumns($table)
    {
        #$sql = 'EXEC sp_primary_keys_rowset @table_name = ' . $this->conn->quoteIdentifier($table, true);
        $sql = 'EXEC sp_pkeys @table_name = ' . $this->conn->quoteIdentifier($table, true);

The changes inside the Doctrine Plugin are not clean, it should be an accrodingly extension, but it worked for my quick requirement to generate a schema out of the database.

EDIT:

For some reason I got again an error while trying to build the schema out of the SQL Azure database:

SQLSTATE[42000]: Syntax error or access violation: 156 [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near the keyword ‘File’. (SQLExecute[156] at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: “EXEC sp_pkeys @table_name = File”

and

SQLSTATE[42000]: Syntax error or access violation: 156 [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near the keyword ‘File’. (SQLExecute[156] at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: “EXEC sp_columns @table_name = File”

To solve the problem I need to modifie the change I did in

symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Import/Mssql.php:

    public function listTableColumns($table)
    {
        #$sql = 'EXEC sp_primary_keys_rowset @table_name = ' . $this->conn->quoteIdentifier($table, true);
        $sql = 'EXEC sp_pkeys @table_name = ' . $this->conn->quoteIdentifier($table, false);
        ...
        #$sql     = 'EXEC sp_columns @table_name = ' . $this->conn->quoteIdentifier($table, true);
        $sql     = 'EXEC sp_columns @table_name = ' . $this->conn->quoteIdentifier($table, false);

I changed the 2nd quoteIdentifier parameter to “false“.


Eclipse: javax.crypto.BadPaddingException

Today I just wanted to add the Windows Azure Certificate to my Eclipse IDE (WindowsAzure4e).
I misstyped the cert password and get this error:

javax.crypto.BadPaddingException: Given final block not properly padded

But then I didn’t get the dialog again to enter the right password.

To get this problem solved you need to delete the imported windows azure certs settings in eclipse.

To do so just delete this folder:

ECLIPSE_WORKSPACE/.metadata/.plugins/org.soyatec.windows.azure.core

Then you can repeat adding the certificate.

Maybe it also helps to delete the certificate completely from your system. To do so start the windows cert manger:

Start -> Search -> certmgr.msc -> Enter

Search for the installed cert in the different cert folders and delete it.


Windows Azure and symfony 1.4 important php.ini settings

When you try to get symfony running (for instance with windowsazure4e) there will occur some problems with the deployed version.

I could solve the problems with these very important php.ini settings:

  • Locate the “cgi.force_redirect” setting and remove the comment and set the value to “0“‘ (Note: 0 for IIS and 1 for Apache or iPlanet).
  • Locate the “cgi.fix_pathinfo” setting and remove the comment. Leave the value as “1” (Note: cgi.fix_pathinfo provides full PATH_INFO/PATH_TRANSLATED support for CGI. Previously the behavior of PHP was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to ignore PATH_INFO. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix its paths to conform to the spec.).
  • Locate the “fastcgi.impersonate” setting and remove the comment, leave the value as “1” (Note: FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.).
  • Locate “extension_dir” and set it to “ext“.

windowsAzure: Web.config settings

To optimize the performance of my WindowsAzure web role I analysed it with the firefox plugin page speed. To pass the several tests I needed to enhance the following settings.

Leverage browser caching:

<system.webServer>
    <staticContent>
      <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
    </staticContent>

I changed the above setting to:

<system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00"  />
    </staticContent>

Because it is strongly not recommend to use high expiration dates, because you can not influence client or proxy cache if the file is already cached. In this example it set it to 1 day.

More Information here.

Specify a Vary: Accept-Encoding header:
<system.webServer>
	  <httpProtocol>
	    <customHeaders>
		    <remove name="Vary"></remove>
		    <add name="Vary" value="Accept-Encoding"></add>
	    </customHeaders>
	  </httpProtocol>

Also I changed here a little bit:

<system.webServer>
	  <httpProtocol>
	    <customHeaders>
		    <remove name="Vary"></remove>
		    <add name="Vary" value="Accept-Encoding, Cookie"></add>
	    </customHeaders>
	  </httpProtocol>

Cookie means in this case to use a different cache version for each session.

EDIT: I removed the “Cookie”-Setting again, because it slows down every page request up to 2  Seconds!

More information here.

Enable compression:

<system.webServer>
    <staticContent>
      <remove fileExtension=".js" />
      <mimeMap fileExtension=".js" mimeType="text/javascript" />
    </staticContent>

    <httpCompression
        directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
        cacheControlHeader="max-age=86400"
			  noCompressionForHttp10="false"
			  noCompressionForProxies="false"
			  sendCacheHeaders="true"
                          minFileSizeForComp="0">
      <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
      <dynamicTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="*/*" enabled="false" />
      </dynamicTypes>
      <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="*/*" enabled="false" />
      </staticTypes>
    </httpCompression>
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />

Not that httpCompression is already enabled by default, but the default setting for minFileSizeForComp ist 2700kB, so small files will be ignored. Furthermore I disabled the compression for HTTP1.0 and Proxies, because older browser sometime have problems with it.

The modification of the mimeMap is done because of the different mimeTypes for JavaScript, so we give all .js files the same mime type which will be compressed.


WindowsAzure: Remote Desktop

I needed some research to find out how to configure a WindowsAzure web role manually to activate Remote Desktop.

Here are the settings:

ServiceDefinition.csdef:

 <WebRole>
   ...
   <Imports>
     <Import moduleName="RemoteAccess" />
     <Import moduleName="RemoteForwarder" />
   </Imports>
 </WebRole>

Each role of the deployments which needs RDP requires the module “RemoteAccess”. Only one role needs to import the module “RemoteForwarder”.

ServiceConfiguration.cscfg

 <Role name="WorkerRole">
   <Instances count="2" />
   <ConfigurationSettings>
     ...
     <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
     <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" value="jimoneil" />
     <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" value="ENC_PASSWORD" />
     <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" value="2011-01-27T23:59:59.0000000-05:00" />
    <Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
   </ConfigurationSettings>
   <Certificates>
     <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption"
                  thumbprint="CERTIFIKATE_THUMBPRINT"
                  thumbprintAlgorithm="sha1" />
   </Certificates>
 </Role>

“RemoteForwarder” only needs to be activiated for the forwarder role. Follow the link below for a generate password how-to. The thumbprint can be found in the management portal.

Links


Copyright © 2007-2012 iTopia. All rights reserved.
Jarrah theme by Templates Next | Powered by WordPress