Zend_Feed: white screen of death on Production, works perfectly on Dev Server - zend-framework

A few weeks ago I noticed that the RSS feed on my live site was broken - I get a white screen of death. It had worked fine up until then. The rest of my site continues to work fine. Additionally the identical code continues to work perfectly on my dev box.
No code changes have occurred, so I'm guessing my web host have changed a server setting - but I've no idea what the setting may be (so I don't know if there's a workaround or if I need to ask my web host to change something). Both Prod & Dev are running PHP 5.3.8.
Could anyone give me a clue as to what that setting might be?
The only major difference I could see in the response headers was that my (non-working) Production RSS feed has this Response Header: "Accept-Ranges: none".
I've double-checked the DB call that populates the feed, and even replaced it with some static data within the class (just in case there was a DB problem), but it makes no difference.
Code for the relevant Controller method below:
public function articlesAction(){
$format = $this->_request->getParam('format');
//default format to rss if unspecified
$format = in_array($format, array('rss','atom')) ? $format : 'rss';
$articles = new Application_Model_DbTable_Articles();
$rows = $articles->getLatestArticlesForFeed();
$channel = array(
'title' => 'Feed of articles',
'link' => 'http://www.mysite.co.uk',
'description' => 'The latest articles and reviews from my site',
'author' => 'My name',
'language' => 'en',
'ttl' => '60',
'copyright' => '© the writers of the articles',
'charset' => 'utf-8',
'entries' => array()
);
foreach ($rows as $item) {
$articlelink = 'http://www.mysite.co.uk/articles/' . $item['stub'];
$formattedlink = '<p><strong>Source: '.$articlelink.'</strong></p>';
$channel['entries'][] = array(
'title' => $item['title'],
'link' => $articlelink,
'guid' => $articlelink,
'description' => $formattedlink . $item['content'] . '<p>© ' . $item['byline'] . ', ' . $item['copyright'] . '</p>' ,
'lastUpdate' => strtotime($item['date_published'])
);
}
$feed = Zend_Feed::importArray($channel, $format);
$feed->__wakeup();
}
$feed->send();
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout()->disableLayout();
}

I wasted an hour once figuring out why I have a WSOD just because I initiated a class with one lowercase letter...
$table = new Model_DbTable_EshopSubcategories(); instead of
$table = new Model_DbTable_EshopSubCategories();
The dev server does not have to be case sensitive and the production server can.

Related

mojolicious need all the time out time for load a page on production with hypnotoad

There is one page on my Mojolicious project that loads correctly but then the connections doesn't finish until arrive to the timeout time.
I got the problem only with hypnotoad on production server.
I couldn't replicate the problem on development.
I have been one day investigating the issue due the page was doing and api request to an external service.
Initially I was thinking it was due to some Mojo::UserAgent problem and I have been trying multiple combinations of Promise and IOLoop and anyone was working.
the code simplified is:
sub show {
my $s = shift;
my $customer = Model::Customers->new();
$customer->id( $s->session('id') );
$customer->get();
my $subscription = Model::Customers::Subscriptions->new();
$subscription->id( $s->session('id') );
$subscription->get();
my $plan = Model::Plans->new();
$plan->id( $subscription->idPlan );
$plan->get;
$s->stash(
namePlan => $plan->name,
monthDuration => $plan->monthDuration,
amount => $plan->amount,
end => $subscription->end,
status => $subscription->status,
signupDate => $customer->signupDate,
endTrial => $customer->endTrial,
diffTrial => $customer->diffTrial,
trialDays => $customer->trialDays,
startSubscription => $subscription->start,
discount => $plan->discount,
newsletter => $newsletter,
);
$s->render();
}
I don't share template code because isn't necessary.
The page and template load correctly but the browser, chrome, stay loading until arrive to the timeout. (15s default)
The reason of the problem is that I was using a reserved stash word 'status'.
The solution is change the name of the variable on stash and in the template:
$s->stash(
namePlan => $plan->name,
monthDuration => $plan->monthDuration,
amount => $plan->amount,
end => $subscription->end,
subStatus => $subscription->status,
signupDate => $customer->signupDate,
endTrial => $customer->endTrial,
diffTrial => $customer->diffTrial,
trialDays => $customer->trialDays,
startSubscription => $subscription->start,
discount => $plan->discount,
newsletter => $newsletter,
);

Google cloud storage: How can I reset edge cache?

I updated an image (from PHP) but still the old version of the image is downloaded.
If I download the image on the GCS console, I can download the new version of the image. However, this url below returns the old version.
https://storage.googleapis.com/[bucket name]/sample-image.png
It seems that the old image is on the Google's edge cache.
Some articles say that I should delete the image object then insert the new image object so that the edge cache is cleared.
Does anyone know about this?
Update 1
This is my PHP code which is on GCE.
$obj = new \Google_Service_Storage_StorageObject();
$obj->setName($path . "/" . $name);
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
$storage = new \Google_Service_Storage($client);
$bucket = 'sample.com';
$binary = file_get_contents($_FILES['files']['tmp_name']);
$fileInfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $fileInfo->buffer($binary);
$storage->objects->insert($bucket, $obj, [
'name' => $path . "/" . $name,
'data' => $binary,
'uploadType' => 'media',
'mimeType' => $mimeType,
]);
It seems that only these parameters are valid. I don't think I can set any cache settings.
// Valid query parameters that work, but don't appear in discovery.
private $stackParameters = array(
'alt' => array('type' => 'string', 'location' => 'query'),
'fields' => array('type' => 'string', 'location' => 'query'),
'trace' => array('type' => 'string', 'location' => 'query'),
'userIp' => array('type' => 'string', 'location' => 'query'),
'quotaUser' => array('type' => 'string', 'location' => 'query'),
'data' => array('type' => 'string', 'location' => 'body'),
'mimeType' => array('type' => 'string', 'location' => 'header'),
'uploadType' => array('type' => 'string', 'location' => 'query'),
'mediaUpload' => array('type' => 'complex', 'location' => 'query'),
'prettyPrint' => array('type' => 'string', 'location' => 'query'),
);
https://github.com/google/google-api-php-client/blob/master/src/Google/Service/Resource.php
I tried this way but not work so far. This is for only GAE...? (Or mounting may be necessary)
$image = file_get_contents($gs_name);
$options = [ "gs" => [ "Content-Type" => "image/jpeg"]];
$ctx = stream_context_create($options);
file_put_contents("gs://<bucketname>/".$fileName, $gs_name, 0, $ctx);
How do I upload images to the Google Cloud Storage from PHP form?
Update 2
API doc shows cacheControl property of Request body. I guess that using API directly (not via SDK) is a way. I will try it.
https://cloud.google.com/storage/docs/json_api/v1/objects/insert
cacheControl string Cache-Control directive for the object data. writable
I think I found it finally!
$obj->setCacheControl('no-cache');
Update 3
$bucket_name = 'my-bucket';
$file = "xxx.html";
$infotowrite = "999";
$service = new Google_Service_Storage($client);
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file);
$obj->setCacheControl('public, max-age=6000');
$results = $service->objects->insert(
$bucket_name,
$obj,
['name' => $file, 'mimeType' => 'text/html', 'data' => $infotowrite, 'uploadType' => 'media']
);
Set Cache-Control php client on Google Cloud Storage Object
We can check the result
gsutil ls -L gs://...
By default, if an object is publicly accessible to all anonymous users and you do not otherwise specify a cacheControl setting, GCS will serve a Cache-Control header of 3600 seconds, or 1 hour. If you're getting stale object data and haven't been messing with cache control settings, I assume you're serving publicly accessible objects. I'm not sure if Google itself is caching your object data or if there's some other cache between you and Google, though.
In the future, you can fix this by explicitly setting a shorter Cache-Control header, which can be controlled on a per-object basis with the cacheControl setting.
Right now, you can probably get around this by tacking on some made up extra URL query parameter, like ?ignoreCache=1
More: https://cloud.google.com/storage/docs/xml-api/reference-headers#cachecontrol

Symfony2 - Functional Testing File uploads with dynamically created fields

I'm fighting with functional testing of files uploading.
I will try to simplify my situation. Let's say I have
a company entity, which has 3 fields.
Company {
protected name;
protected tags;
protected images;
}
Images is array of CompanyImage entities, which serve for
storing image files and tags contains array of Tag entities,
which can be m:n connected with companies.
In the form I use jquery, for adding tags and images dynamically.
(you can create images and add them to the company similar to the
collection type symfony tutorial)
Because images and tag arrays are created with jquery, I cannot
simply use something like the turorial line below in the functional test of the company form.
$form['images'][0]->upload('/path/to/image.jpg');
For the setting
of the form values I use simple a little trick described by sstok here
(https://github.com/symfony/symfony/issues/4124)
public function testCompanyCreation() {
...
//option1
$image = new UploadedFile(
'/path/to/image.jpg',
'image.jpg',
'image/jpeg',
123
);
//or option2
//$image = array('tmp_name' => '/path/to/image.jpg', 'name' => 'image.jpg', 'type' => 'image/jpeg', 'size' => 300, 'error' => UPLOAD_ERR_OK);
$companyFormNode = $companyCrawler->selectButton('Create');
$companyForm = $companyFormNode->form();
$values = array(
'company' => array(
'_token' => $companyForm['company[_token]']->getValue(),
'name' => 'test company',
'tags' => array('1'),
'images' => array('0' => (array('file' =>$image))),
),
);
$companySubmitCrawler = $client->request($companyForm->getMethod(), $companyForm->getUri(), $values, $companyForm->getPhpFiles());
}
this works perfectly until I try to upload the image file.
With the option1 I get following exception
Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed
when I use option2 I get this
Argument 1 passed to Acme\myBundle\Entity\CompanyImage::setFile() must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile, array given, called in ...\PropertyAccess\PropertyAccessor.php on line 347 and defined (500 Internal Server Error)
I would also like to point out, that the whole form and uploading of the files works without any problems in the browser. I also tried to make the entities serializable, and it didn't help. Do I have a bug somewhere?
I have figured it out (took couple of hours). Files have to be uploaded in a separate array.
$companyForm = $companyFormNode->form();
$values = array(
'company' => array(
'_token' => $companyForm['company[_token]']->getValue(),
'name' => 'test company',
'tags' => array('1')
),
);
$files = array(
'company' => array('images' => array('0' => (array('file' => $image))))
);
$companySubmitCrawler = $client->request(
$companyForm->getMethod(),
$companyForm->getUri(),
$values,
$files
);

Can someone provide a php sample using nusoap/sugarcrm api to create an acct/lead in sugarcrn?

Can someone provide a sample code chunk of php using the sugarcrm API/nusoap for adding creating an acct. and then linking a lead to the acct?
I've got a sample function that adds a lead, and I can see how to create an acct, but I can't see how to tie a lead to the acct, to simulate the subpanel process in the sugarcrm acct/subpanel process.
thanks
// Create a new Lead, return the SOAP result
function createLead($data)
{
// Parse the data and store it into a name/value list
// which will then pe passed on to Sugar via SOAP
$name_value_list = array();
foreach($data as $key => $value)
array_push($name_value_list, array('name' => $key, 'value' => $value));
// Fire the set_entry call to the Leads module
$result = $this->soap->call('set_entry', array(
'session' => $this->session,
'module_name' => 'Leads',
'name_value_list' => $name_value_list
));
return $result;
}
$result = $sugar->createLead(array(
'lead_source' => 'Web Site',
'lead_source_description' => 'Inquiry form on the website',
'lead_status' => 'New',
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email1' => $_POST['email'],
'description' => $_POST['message']
));
You need to find the ID for the account and assign that ID to whatever the account_id field name is in the Lead Module. I have run into a couple things like this before and I have found it easier to go straight to the Sugar database. So, write a statement that will return the account is, for example: SELECT id WHERE something_in_the_account_table = something else;
Then you can assign that id in your $result array. I hope it helps. I didn't have any code or documentation in front of me or I would have helped more.

SoundCloud API: Tweeting on upload and disable comments

The following PHP code uploads a new track to SoundCloud successfully, but the tweet is not sent.
Is there something I need to have in there as well in order to do this?
$track = $soundcloud->post('tracks',
array(
'track[asset_data]' => '#audio.mp3',
'track[title]' => "my audio",
'track[description]' => "Updated: " . date('l jS F Y h:i:s A'),
'track[sharing]' => 'public',
'track[shared_to][connections][][id]' => '123',
'track[sharing_note]' => 'Have a listen to'
));
Also I'd like to be able to disable comments on the audio I upload, but I wasn't sure what the parameter for that would be too?
Thanks!
dB
I'm unable the repro the sharing problem. Please note that sometimes sharing on other social networks doesn't happen right away. Are you still having trouble? Here's the code I used:
<?php
require_once 'Services/Soundcloud.php';
$client = new Services_Soundcloud("foo", "bar");
$client->setAccessToken('ACCESS_TOKEN');
$track = $client->post('tracks', array(
'track[title]' => 'Foooo',
'track[asset_data]' => '#/Users/paul/audio.wav',
'track[sharing]' => 'public',
'track[shared_to][connections][][id]' => 'CONNECTION_ID',
'track[sharing_note]' => 'Check it out'
));
print_r($track);
Also verify that your CONNECTION_ID is correct. Some code to get a list of connections so you can verify the id:
<?php
require_once 'Services/Soundcloud.php';
$client = new Services_Soundcloud("foo", "bar");
$client->setAccessToken('ACCESS_TOKEN');
print_r(json_decode($client->get('me/connections')));
Unfortunately there's no way currently to disable comments via the API. I'll file a bug and see about getting this fixed.
Hope that helps!