1

I want to update an option which is an array by adding a new value, but there's no atomicity or guarantee of data integrity.

EXAMPLE

//Get the option value (an array)
$val = get_option( "some-option" );

//Add to the array
$val[] = "something";

/** Here, another session might already have it and is calling "update_option" */

//Save back (this overwrites whatever that other person did)
update_option( "some-option", $val );

Is there anything in wordpress that offers atomicity?

9
  • You should try using the Settings API. Apr 24, 2014 at 16:09
  • @ChipBennett How would that be any different? Altering an array stored in a setting would still be non-atomic. Is there a settings API call to lock a setting until unlocked? (I couldn't find it)
    – Don Rhummy
    Apr 24, 2014 at 16:11
  • 2
    Essentially no, there is no locking mechanism for this in WordPress core.
    – Rarst
    Apr 24, 2014 at 16:16
  • 3
    Why are front-end user data being stored as an option? You're describing content, which gets stored as posts. Apr 24, 2014 at 16:29
  • 1
    I think @ChipBennett is on the right track. It is starting to sound like the problem is with your data design not with how options work.
    – s_ha_dum
    Apr 24, 2014 at 16:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.