Engineering and Developers Blog
What's happening with engineering and developers at YouTube
PHP Client Library: Uploading videos now 99% more efficient !
Monday, March 2, 2009
Posted by Jochen Hartmann, YouTube APIs and Tools Team
If you are using the
PHP Client Library
to upload your videos to YouTube.com you may have had to deal with memory issues, such as the common
Fatal error: Allowed memory size of ... bytes exhausted
error message.
I am happy to announce that
as of version 1.7.6 of the client library
, this should no longer be a problem. Jeff Fisher and I have added support for streaming large video files to our API in manageable 1 MB chunks. The change is completely transparent, so you won't need to do anything besides upgrade your copy of the client library.
Prior to this change, our client library used to rely solely on the
Zend_Http_Client
object to handle HTTP communication between servers. The client makes requests by reading the entire body of your
HTTP POST
message into a string, which then gets sent to our API server. This behavior is perfectly acceptable for normal use since most of the time we are just sending XML strings or small media files such as images, but doesn't work quite so well for uploading 1 GB video files.
To address this problem, I designed a
Zend_Gdata_MediaMimeStream
object which only stores a handle to the video file being uploaded. Jeff built a
Zend_Gdata_HttpAdapterStreamingSocket
which then reads from the media stream in 1 MB chunks and sends to the socket until the entire message is read. We have tested this code extensively and are always open to feedback on how to improve performance issues in our client library, so
check out the source code
if you are interested.
While I have your attention, let me also share another trick for those obsessed with efficiency: If you are only interested in working with the raw XML instead of the complete Zend_Gdata object model, you can
flip a minor switch
that is available in all of our service classes (Zend_Gdata_YouTube, Zend_Gdata_Docs, etc.):
$yt = new Zend_Gdata_YouTube();
$yt->useObjectMapping(false);
$xmlString = $yt->getRecentlyFeaturedVideoFeed();
echo gettype($xmlString); # will return 'string'
As you can see in the snippet above, the
$xmlString
variable is now just a regular string instead of a
Zend_Gdata_VideoFeed
object. My testing shows that this can make fetching video feeds from YouTube faster by up to 35 times. Of course you would need to add a little bit of time parsing the XML with the tool of your choice (
XPath
, etc.). I should also add that those interested in parsing XML without the aid of the client library may want to check out the
Backward Compatibility Guidelines
for the YouTube Data API.
No comments :
Post a Comment
Labels
.net
acceleration
access control
accessibility
actionscript
activities
activity
android
announcements
apis
app engine
appengine
apps script
as2
as3
atom
authentication
authorization
authsub
best practices
blackops
bootcamp
captions
categories
channels
charts
chrome
chromeless
client library
clientlibraries
clientlogin
code
color
comments
compositing
create
curation
custom player
decommission
default
deprecation
devs
direct
discovery
docs
Documentation RSS
dotnet
education
embed
embedding
events
extension
feeds
flash
format
friendactivity
friends
fun
gears
google developers live
google group
googlegamedev
googleio
html5
https
iframe
insight
io12
io2011
ios
iphone
irc
issue tracker
java
javascript
json
json-c
jsonc
knight
legacy
Live Streaming API
LiveBroadcasts API
logo
mashups
media:keywords keywords tags metadata
metadata
mobile
mozilla
news
oauth
oauth2
office hours
open source
partial
partial response
partial update
partners
patch
php
player
playlists
policy
previews
pubsubhubbub
push
python
quota
rails
releases
rendering
reports
responses
resumable
ruby
samples
sandbox
shortform
ssl https certificate staging stage
stack overflow
stage video
staging
standard feeds
storify
storyful
subscription
sup
survey
tdd
theme
tos
tutorials
updates
uploads
v2
v3
video
voting
watch history
watchlater
webvtt
youtube
youtube api
youtube developers live
youtube direct
ytd
Archive
2015
December
November
October
May
April
March
January
2014
October
September
August
May
March
2013
December
October
September
August
July
June
May
April
March
February
2012
December
November
September
August
July
June
May
April
March
February
January
2011
December
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
July
June
May
April
March
February
January
2009
November
October
September
August
July
June
May
April
March
Recent activity: apitestjhartmann has written a tu...
Latest .NET SDK Released! LINQ & New Social Notifi...
PHP Client Library: Uploading videos now 99% more ...
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
2007
December
November
August
June
May
Feed
YouTube
on
Follow @youtubedev
No comments :
Post a Comment