- This topic is empty.
-
AuthorPosts
-
April 12, 2013 at 2:24 am #44058
Htmlmainiac
MemberHi lovely CSS-TRICKS community,
I have a problem here i’m trying to use the Usream api to make a search then get the file from their server to mine but i keep getting
> Fatal error: Out of memory
even though i did
ini_set(‘memory_limit’, ’70M’);
set_time_limit(0);And here is my hole code:
ini_set(‘error_reporting’, E_ALL);
ini_set(‘memory_limit’, ’70M’);
set_time_limit(0);require_once(‘./func/Zend.php’);
class UstreamToYouTube {
private $key = ‘F8CF0D132889AEC1A0D6D14B65B220A9’,
$title = ‘BochTV’,
$c,
$url,
$options = array(CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0’),
$reponse,
$results;function __construct() {
$this->url = ‘http://api.ustream.tv/php/video/recent/search/title:like:’ . urlencode($this->title) . ‘?key=’ . $this->key;
$this->c = curl_init($this->url);
curl_setopt_array($this->c, $this->options);
$this->response = curl_exec($this->c);
$this->results = unserialize($this->response);
$this->results = $this->results;
}public function init() {
$dir = scandir(dirname(__FILE__) . ‘/files/’);
$i = 0;
$l = (count($dir) – 1);
foreach ($this->results as $result) {
global $i, $l;
if ($i < $l) {
global $i, $l;
$i++;
} else if ($i == $l) {
$a = substr($result, 0, 2);
$b = substr($result, 0, 5);
$c = $result;
$d = $result;
$url = ‘http://upmv09.ntt.upmv.ustream.tv/0/1/’ . $a . ‘/’ . $b . ‘/1_’ . $c . ‘_’ . $d . ‘.flv’;
$fp = fopen(dirname(__FILE__) . ‘/files/’ . $d . ‘.flv’, “w”);
$options = array(
CURLOPT_TIMEOUT => 28800,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true
);print_r($options);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
fwrite($fp, curl_exec($ch));
sleep(3);
}
}
require_once(dirname(__FILE__) . ‘/YouTube.php’);
}
}$ustoyt = new UstreamToYoutube();
$ustoyt->init();Please can someone tell me why this is happening.
April 12, 2013 at 2:55 am #131483__
ParticipantAre you on a shared host?
You probably won’t get this to work without a dedicated server.
There are any number of places that a configuration might be preventing you from raising the memory limit (at all, or past a certain point). Might be Suhosin, safe_mode (*shudder*), Apache itself … it’s quite common on shared hosts. They don’t want one user hogging the CPU.
April 12, 2013 at 5:42 pm #131650__
ParticipantAs I said, if you don’t have a dedicated server, you probably won’t be able to do this.
Do you have a dedicated server?
April 12, 2013 at 5:44 pm #131651CrocoDillon
ParticipantI’m having a hard time trying to figure out what your init function actually does. And why you declare variables global after defining them in a class method with `global $i, $l;`.
April 12, 2013 at 6:57 pm #131657__
Participant[Everything here](http://v1.srcnix.com/2010/02/10/7-tips-to-prevent-php-running-out-of-memory/) is great advice.
You can also use [gc_collect_cycles()](http://php.net/gc_collect_cycles) to make PHP clean up after itself more often. It _might_ be helpful for you to call that at the beginning of each loop.
But CrocoDillon is right about that code – there’s about eight lines in a row that repeatedly do the same, nonsensical things.
April 13, 2013 at 10:01 am #131710__
ParticipantHow big are the writes you’re making? Can you break it into smaller chunks and gc between loops?
April 17, 2013 at 5:10 pm #132199__
Participant> Do you have a dedicated server?
.
> How big are the writes you’re making?.
> And why you declare variables global after defining them in a class method *[?]*
( @Crocodillon )Did you try gc’ing inside your loop?
Did you check if there is a server setting limiting the memory you use?
April 17, 2013 at 5:14 pm #132201__
Participantwhich question are you answering?
April 17, 2013 at 5:21 pm #132205ghafirsayed
MemberBecause Htmlmainiac doesn’t know himself what he is asking. He is just spaming on css-tricks , has already made a complain.
April 17, 2013 at 5:23 pm #132206ghafirsayed
MemberLook here, just entering links(probably assuming that if he enters links twice he would get two backlinks (: )
https://css-tricks.com/forums/discussion/24241/how-do-you-center-div-in-css#Item_7
April 17, 2013 at 5:31 pm #132209Htmlmainiac
MemberSort thought it had croped off the end but I haden’t.
April 17, 2013 at 5:58 pm #132215__
Participant> Do you have a dedicated server?
>> don’t knowThat probably means you don’t.
Therefore, my first comment applies:
> You probably won’t get this to work without a dedicated server.
*****
> How big are the writes you’re making?
>> 20 min flvThat’s not a size.
What I am asking is how much data (i.e., in *bytes*) you are trying to write at once.
*****
> And why you declare variables global after defining them in a class method [?]( @Crocodillon )
>> yesThat wasn’t a yes-or-no question.
*****
What about garbage collection? Did you try? What were your results?*****
What about your server settings? Did you check on safe mode, Suhosin, or other Apache settings? Ask your web host if you don’t know how to check these things. -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.