Search Results

Search found 2 results on 1 pages for 'kristovaher'.

Page 1/1 | 1 

  • Can you catch exceeded allocated memory error before it kills the script?

    - by kristovaher
    The thing is that I want to catch memory problems before they happen. I have a system that gets rows from database and casts the returned associative array to a variable, but I never know what the size of the database result is is or how much memory it will take once the database request is made. This means that my software can fail simply because memory is exceeded. But I want to avoid that somehow. One of the ways is to obviously make database requests that are smaller, but what if this is not possible or what if I do not know the size of data that is returned from database? Is it possible to 'catch' situations where memory use is exceeded in PHP? Something like this: $requestOk=memory_test(function(){ return doSomething(); }); if($requestOk){ // Memory seems fine // $requestOk now has the value from memory_test() function } else { // Function would have exceeded memory } I just find it problematic that my script can just die at any moment because of memory issues. From what I know, try-catch cannot be used here because it is a fatal error. Any help would be appreciated!

    Read the article

  • This process does not work in JavaScript: createElement() -> setAttribute('id') -> getElementById()

    - by kristovaher
    I was so sure that this question has been answered a thousand times before, but I've been unable to find an answer in StackOverflow. If there is already an answer and I was unable to find it then I apologize. I create hidden form elements dynamically like this: submitForm=document.getElementById('my-form'); var element=document.createElement('input'); element.id='hidden-form-data'; // or setAttribute('id','hidden-form-data'); element.name='my-hidden-form-data'; element.type='hidden'; element.value='my-data'; submitForm.appendChild(element); This works and the input field is created and it is taken into account when submitting the form. But I want to remove it after I have dynamically created it. I was sure that creating a new node this way would be 'correct' for browser and DOM, but apparently it is not. This returns null: element=document.getElementById('hidden-form-data'); if(element!=null){ element.parentNode.removeChild(element); } But it never gets removed and is always null. Is there any way I can remove a dynamically created node with an ID? Thank you! Please do not suggest jQuery, it's not possible to use jQuery for this, footprint is too heavy for such a small task I could not get a working answer from here, which was the closest thread I could find.

    Read the article

1